{"action":"created","issue":{"url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/9","labels_url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/9/comments","events_url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/9/events","html_url":"https://github.com/froatsnook/meteor-shopify/issues/9","id":116031691,"number":9,"title":"Keyset Persistence","user":{"login":"dbnoble","id":3032305,"avatar_url":"https://avatars.githubusercontent.com/u/3032305?v=3","gravatar_id":"","url":"https://api.github.com/users/dbnoble","html_url":"https://github.com/dbnoble","followers_url":"https://api.github.com/users/dbnoble/followers","following_url":"https://api.github.com/users/dbnoble/following{/other_user}","gists_url":"https://api.github.com/users/dbnoble/gists{/gist_id}","starred_url":"https://api.github.com/users/dbnoble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbnoble/subscriptions","organizations_url":"https://api.github.com/users/dbnoble/orgs","repos_url":"https://api.github.com/users/dbnoble/repos","events_url":"https://api.github.com/users/dbnoble/events{/privacy}","received_events_url":"https://api.github.com/users/dbnoble/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-10T05:42:34Z","updated_at":"2015-11-10T09:07:42Z","closed_at":null,"body":"Why are we persisting the keysets in memory instead of simply storing them in a collection on the database? \r\n\r\nEspecially since there is no way to check if a current keyset exists, the keyset has to be reestablished constantly to be fully reliable. Every time you push code, the keysets will all be flushed. "},"comment":{"url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/comments/155363378","html_url":"https://github.com/froatsnook/meteor-shopify/issues/9#issuecomment-155363378","issue_url":"https://api.github.com/repos/froatsnook/meteor-shopify/issues/9","id":155363378,"user":{"login":"froatsnook","id":10405574,"avatar_url":"https://avatars.githubusercontent.com/u/10405574?v=3","gravatar_id":"","url":"https://api.github.com/users/froatsnook","html_url":"https://github.com/froatsnook","followers_url":"https://api.github.com/users/froatsnook/followers","following_url":"https://api.github.com/users/froatsnook/following{/other_user}","gists_url":"https://api.github.com/users/froatsnook/gists{/gist_id}","starred_url":"https://api.github.com/users/froatsnook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/froatsnook/subscriptions","organizations_url":"https://api.github.com/users/froatsnook/orgs","repos_url":"https://api.github.com/users/froatsnook/repos","events_url":"https://api.github.com/users/froatsnook/events{/privacy}","received_events_url":"https://api.github.com/users/froatsnook/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T09:07:42Z","updated_at":"2015-11-10T09:07:42Z","body":"The intention was to leave this up to the library user.\r\n\r\nI have two apps in production, and each is handled differently:\r\n\r\nOne uses private API, and there I store the credentials in `settings.json` and call `Shopify.addKeyset` in `Meteor.startup` on the server.\r\n\r\nThe other uses the public API.  This one has multiple users per client (with one shop per client).  So after a user authenticates, the credentials are stored in the Clients collection, and then I memoize the shopify API object for each client:\r\n\r\n```javascript\r\n// server/lib/ShopifyGetAPI.js\r\n\r\n// Cache API objects per shop.\r\n//\r\n// shop => Shopify.API\r\nvar apis = { };\r\n\r\n// Get Shopify API access object for a client.\r\n//\r\n// @param clientId {String} _id of client.\r\nShopifyGetAPI = function(clientId) {\r\n    check(clientId, NonEmptyString);\r\n    var client = Clients.findOne(clientId);\r\n\r\n    var shop = client.services.shopify.shop;\r\n    var access_token = client.services.shopify.access_token;\r\n    check(shop, String);\r\n    check(access_token, String);\r\n\r\n    if (!apis[shop]) {\r\n        apis[shop] = new Shopify.API({\r\n            shop: shop,\r\n            access_token: access_token,\r\n            debug: true\r\n        });\r\n    }\r\n\r\n    return apis[shop];\r\n};\r\n```\r\n\r\nIn other words, the first time you start using `Shopify.API` for a client, it gets the credentials from the database.  Since we provide the `access_token` directly, creating a keyset manually isn't necessary.\r\n\r\nDoes that make sense?  Would something like this be sufficient for you?  It would be easy to add something like `Shopify.keysetExists` (as a workaround for now you could do something like `keyset in Shopify._keysets`).  I'm not sure how I feel about automatically putting them in the database.  But `Shopify.persistKeysets = true` sounds doable!"}}