{"_id":"55918fec5631432f002d357e","category":{"_id":"5567425a1c38390d0069808b","project":"556742591c38390d00698087","__v":16,"pages":["5567425c1c38390d0069808d","558f782c1311b80d00ba9d97","558f7986f795be2d00c1164f","558f8069f795be2d00c11655","558f810bf795be2d00c11657","558f82e11311b80d00ba9da1","558f850df795be2d00c1165b","558f85401311b80d00ba9da3","558f85df1311b80d00ba9da5","558f87726742610d0051c4f5","558f87f26742610d0051c4f7","558f886df795be2d00c1165f","55918fec5631432f002d357e","559191f34e50b50d0019612a","5592c8d89a68220d00f1c404","559efaebdf92223500dc50e7"],"version":"5567425a1c38390d0069808a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-28T16:29:14.942Z","from_sync":false,"order":9999,"slug":"documentation","title":"Documentation"},"version":{"_id":"5567425a1c38390d0069808a","project":"556742591c38390d00698087","__v":2,"createdAt":"2015-05-28T16:29:14.412Z","releaseDate":"2015-05-28T16:29:14.412Z","categories":["5567425a1c38390d0069808b","57214d354758d90e009e6638"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":1,"parentDoc":null,"project":"556742591c38390d00698087","user":"5564f227f0f70f0d00a9ab20","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-06-29T18:35:24.041Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"Generate a session token for a device in the Meshblu device registry. In order to generate a token, your connection must be authenticated as a device that is in the target device's `configure.update` whitelist. See the [Meshblu whitelist documentation](https://meshblu.readme.io/docs/whitelists-2-0) for more information.\n\n### Event: `\"generateAndStoreToken\"`, `query`, `callback`\n\n* `query` Query object, must contain only the `uuid` property.\n  * `uuid` UUID of the device to generate a token for.\n* `callback` Function that will be called with a `result`.\n  * `result` Object passed to the callback. Contains either the (`uuid`, `token`, `createdAt`) triplet, or `error` key, but never both.\n    * `uuid` The uuid for which a token was generated\n    * `token` The token that was generated in plain-text form. *This is the only time that token will ever be shown. If it is not saved at this point, it can never be retreived*\n    * `createdAt` An ISO 8601 timestamp for when the token was generated.\n    * `error` String explaining the what went wrong. Is only present if something went wrong.\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Check the permissions\",\n  \"body\": \"In order to generate a token, your connection must be authenticated as a device that is in the target device's `configure.update` whitelist. See the [Meshblu whitelist documentation](https://meshblu.readme.io/docs/whitelists-2-0) for more information.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"In Meshblu, it is not possible to distinguish between a device not existing and not having permission to view a device. In most of the Meshblu API calls, the error in both cases yields the protocol-specific equivalent of an `HTTP 404: Not Found`. The Socket.IO API, however, returns the error `Forbidden`. This is for backwards compatibility and will likely change with the next major version release of the Socket.IO API.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Successful Response\"\n}\n[/block]\nWhen generateAndStoreToken is called for a valid device that the authorized device may update:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"uuid\\\": \\\"78159106-41ca-4022-95e8-2511695ce64c\\\",\\n  \\\"createdAt\\\": \\\"2016-05-20T18:25:13.587Z\\\",\\n  \\\"token\\\": \\\"8234f58b65ff042da60d84af4230d3692778ca5b\\\"\\n}\\n\",\n      \"language\": \"json\",\n      \"name\": \"response.json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Error Response\"\n}\n[/block]\nWhen generateAndStoreToken is called for a non-existing devices, or devices the authenticated device may not update:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"error\\\": \\\"Forbidden\\\"\\n}\\n\",\n      \"language\": \"json\",\n      \"name\": \"error-response.json\"\n    }\n  ]\n}\n[/block]","excerpt":"Generate a session token for a device in the Meshblu device registry.","slug":"generate-and-store-token","type":"basic","title":"Generate and Store Token"}

Generate and Store Token

Generate a session token for a device in the Meshblu device registry.

Generate a session token for a device in the Meshblu device registry. In order to generate a token, your connection must be authenticated as a device that is in the target device's `configure.update` whitelist. See the [Meshblu whitelist documentation](https://meshblu.readme.io/docs/whitelists-2-0) for more information. ### Event: `"generateAndStoreToken"`, `query`, `callback` * `query` Query object, must contain only the `uuid` property. * `uuid` UUID of the device to generate a token for. * `callback` Function that will be called with a `result`. * `result` Object passed to the callback. Contains either the (`uuid`, `token`, `createdAt`) triplet, or `error` key, but never both. * `uuid` The uuid for which a token was generated * `token` The token that was generated in plain-text form. *This is the only time that token will ever be shown. If it is not saved at this point, it can never be retreived* * `createdAt` An ISO 8601 timestamp for when the token was generated. * `error` String explaining the what went wrong. Is only present if something went wrong. [block:callout] { "type": "warning", "title": "Check the permissions", "body": "In order to generate a token, your connection must be authenticated as a device that is in the target device's `configure.update` whitelist. See the [Meshblu whitelist documentation](https://meshblu.readme.io/docs/whitelists-2-0) for more information." } [/block] [block:callout] { "type": "info", "body": "In Meshblu, it is not possible to distinguish between a device not existing and not having permission to view a device. In most of the Meshblu API calls, the error in both cases yields the protocol-specific equivalent of an `HTTP 404: Not Found`. The Socket.IO API, however, returns the error `Forbidden`. This is for backwards compatibility and will likely change with the next major version release of the Socket.IO API." } [/block] [block:api-header] { "type": "basic", "title": "Successful Response" } [/block] When generateAndStoreToken is called for a valid device that the authorized device may update: [block:code] { "codes": [ { "code": "{\n \"uuid\": \"78159106-41ca-4022-95e8-2511695ce64c\",\n \"createdAt\": \"2016-05-20T18:25:13.587Z\",\n \"token\": \"8234f58b65ff042da60d84af4230d3692778ca5b\"\n}\n", "language": "json", "name": "response.json" } ] } [/block] [block:api-header] { "type": "basic", "title": "Error Response" } [/block] When generateAndStoreToken is called for a non-existing devices, or devices the authenticated device may not update: [block:code] { "codes": [ { "code": "{\n\t\"error\": \"Forbidden\"\n}\n", "language": "json", "name": "error-response.json" } ] } [/block]