Simple OAuth2 Reddit
This library is a wrapper around Simple OAuth2 Library
Specially made for Authorization Code Flow with Reddit.
Requirements
Latest Node 8 LTS or newer versions.
Getting started
npm install --save simple-oauth2 simple-oauth2-reddit
or
yarn add simple-oauth2 simple-oauth2-reddit
Usage
const simpleOAuth2Reddit = ;const reddit = simpleOAuth2Reddit;
reddit
object exposes 3 keys:
- authorize: Middleware to request user's authorization.
- getToken: Middleware for callback processing and exchange the authorization token for an
access_token
- oauth2: The underlying simple-oauth2 instance.
Options
Required options
Option | Description |
---|---|
clientId | Your App Id. |
clientSecret | Your App Secret Id. |
callbackURL | Callback configured when you created the app. |
state | Your CSRF anti-forgery token. More at: https://auth0.com/docs/protocols/oauth2/oauth-state |
Other options
Option | Default | Description |
---|---|---|
scope | ['identity'] | https://github.com/reddit-archive/reddit/wiki/OAuth2#authorization |
returnError | false | When is false (default), will call the next middleware with the error object. When is true, will set req.tokenError to the error, and call the next middleware as if there were no error. |
authorizeHost | 'https://www.reddit.com' | |
authorizePath | '/api/v1/authorize' | |
tokenHost | 'https://www.reddit.com' | |
tokenPath | '/api/v1/access_token' | |
authorizeOptions | {} | Pass extra parameters when requesting authorization. |
tokenOptions | {} | Pass extra parameters when requesting access_token. |
Example
Original boilerplate
const oauth2 = ; router; router;
With SimpleOAuth2Reddit
const simpleOAuth2Reddit = ; const reddit = simpleOAuth2Reddit; // Ask the user to authorize.router; // Exchange the token for the access token.router;