Simple OAuth2 Facebook
This library is a wrapper around Simple OAuth2 Library
Specially made for Authorization Code Flow with Facebook.
Requirements
Latest Node 8 LTS or newer versions.
Getting started
npm install --save simple-oauth2 simple-oauth2-facebook
or
yarn add simple-oauth2 simple-oauth2-facebook
Usage
const simpleOAuth2Facebook = ;const facebook = simpleOAuth2Facebook;
facebook
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
SimpleOAuth2Facebook comes with default values for most of the options.
Required options
Option | Description |
---|---|
clientId | Your App Id. |
clientSecret | Your App Secret Id. |
callbackURL | Callback configured when you created the app. |
Other options
Option | Default | Description |
---|---|---|
scope | ['email'] | https://developers.facebook.com/docs/facebook-login/permissions |
state | '' | Your CSRF anti-forgery token. More at: https://auth0.com/docs/protocols/oauth2/oauth-state |
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://facebook.com' | |
authorizePath | '/dialog/oauth' | |
tokenHost | 'https://graph.facebook.com' | |
tokenPath | '/oauth/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 SimpleOAuth2Facebook
const simpleOAuth2Facebook = ; const facebook = simpleOAuth2Facebook; // Ask the user to authorize.router; // Exchange the token for the access token.router;