{"_id":"550ada9e921b7d0d0022888d","category":{"_id":"550ada9d921b7d0d00228878","version":"550ada9d921b7d0d00228876","__v":4,"pages":["550ada9e921b7d0d0022888c","550ada9e921b7d0d0022888d","550ada9e921b7d0d0022888e","550ada9e921b7d0d0022888f","55121961a575b32f007c79f1","55297f32b316811900149fac","5595b553f4437019002888fc"],"project":"550a379f635c660d00527fd8","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-19T02:45:48.278Z","from_sync":false,"order":2,"slug":"authentication","title":"Authentication"},"user":"550a378e635c660d00527fd7","version":{"_id":"550ada9d921b7d0d00228876","forked_from":"550a3b2542fff40d00ae5ffb","project":"550a379f635c660d00527fd8","__v":3,"createdAt":"2015-03-19T14:18:05.245Z","releaseDate":"2015-03-19T14:18:05.245Z","categories":["550ada9d921b7d0d00228877","550ada9d921b7d0d00228878","550ada9d921b7d0d00228879","550ada9d921b7d0d0022887a","550ada9d921b7d0d0022887b","550ada9d921b7d0d0022887c","550ada9d921b7d0d0022887d","5523e61e71c0542100993493","55246f72ccc28a0d0062c560"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0.0"},"__v":10,"project":"550a379f635c660d00527fd8","updates":["563c37c4913e650d00b65dcc"],"next":{"pages":[],"description":""},"createdAt":"2015-03-19T02:52:54.088Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Requirements & Notes\",\n  \"body\": \"- Application must be of type **script**.\\n- The user authenticating must be a developer for the application.\\n\\nRead the [OAuth Overview](doc:oauth-overview) for more information.\"\n}\n[/block]\n## Usage\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Snoocore = require('snoocore');\\n\\nvar reddit = new Snoocore({\\n\\tuserAgent: 'test:::at:::documentation',\\n\\toauth: { \\n\\t\\ttype: 'script',\\n\\t\\tkey: 'client_id from reddit', \\n\\t\\tsecret: 'client_secret from reddit',\\n    username: 'yourUsername',\\n    password: 'yourPassword',\\n    // make sure to set all the scopes you need.\\n\\t\\tscope: [ 'flair', 'identity' ] \\n\\t}\\n});\\t \\n\\n// To authenticate with OAuth, simply call `auth()`\\nreturn reddit('/api/v1/me').get().then(function(result) {\\n\\tconsole.log(result);\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n### Authenticating\n\nAuthentication happens automatically. Refreshing expired access tokens happens automatically as well.\n\nIf you wish to bypass authentication for a call, you can use the call context option `bypassAuth` (See [Call Context Options](doc:call-context-options#)).\n\n### De-Authenticating\n\nA function `reddit.deauth` is provided which will revoke the `access_token` for the current authenticated user.\n\n```javascript\nvar deauthPromise = reddit.deauth();\n```\n\nGenerally it is a good idea to call this every time the application is finished using the users data. Note that if you make another call, Snoocore will automatically re-authenticate with a new access token.","excerpt":"","slug":"oauth-script","type":"basic","title":"Script based OAuth"}

Script based OAuth


[block:callout] { "type": "info", "title": "Requirements & Notes", "body": "- Application must be of type **script**.\n- The user authenticating must be a developer for the application.\n\nRead the [OAuth Overview](doc:oauth-overview) for more information." } [/block] ## Usage [block:code] { "codes": [ { "code": "var Snoocore = require('snoocore');\n\nvar reddit = new Snoocore({\n\tuserAgent: 'test@documentation',\n\toauth: { \n\t\ttype: 'script',\n\t\tkey: 'client_id from reddit', \n\t\tsecret: 'client_secret from reddit',\n username: 'yourUsername',\n password: 'yourPassword',\n // make sure to set all the scopes you need.\n\t\tscope: [ 'flair', 'identity' ] \n\t}\n});\t \n\n// To authenticate with OAuth, simply call `auth()`\nreturn reddit('/api/v1/me').get().then(function(result) {\n\tconsole.log(result);\n});", "language": "javascript" } ] } [/block] ### Authenticating Authentication happens automatically. Refreshing expired access tokens happens automatically as well. If you wish to bypass authentication for a call, you can use the call context option `bypassAuth` (See [Call Context Options](doc:call-context-options#)). ### De-Authenticating A function `reddit.deauth` is provided which will revoke the `access_token` for the current authenticated user. ```javascript var deauthPromise = reddit.deauth(); ``` Generally it is a good idea to call this every time the application is finished using the users data. Note that if you make another call, Snoocore will automatically re-authenticate with a new access token.