Skip to content

jpalumickas/node-oauth2-server-grant-type-facebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OAuth2 Server Facebook Grant Type

Adds Facebook grant type for oauth2-server

Installation

Using Yarn

yarn add oauth2-server-grant-type-facebook

Using NPM

npm install oauth2-server-grant-type-facebook

Usage

Add getUserWithFacebook to oauth2-server model.

  const getUserWithFacebook = async (facebookData) => {
    // Find and return user by Facebook ID

    // Find and return user by Facebook email

    // If not exists create new user
  };

Add Facebook grant type to extendedGrantTypes in oauth2-server options:

  import FacebookGrantType from 'oauth2-server-grant-type-facebook';

  const options = {
    model: ...,
    extendedGrantTypes: {
      facebook: FacebookGrantType,
    }
    requireClientAuthentication: {
      facebook: false,
    },
  }

You can customize what fields to return from Facebook by providing facebookGrantType options in model:

const options = {
  model: {
    ...model,
    facebookGrantType: {
      fields: ['email', 'first_name', 'last_name', 'picture.width(500).height(500)'], // Default: email, first_name, last_name
    }
  }
}

Post request to /oauth/token with facebook grant type:

{
  "grant_type": "facebook",
  "client_id": "YOUR_CLIENT_ID",
  "facebook_token": "FACEBOOK_TOKEN"
}

License

The package is available as open source under the terms of the MIT License.