npm.io
0.4.0 • Published 4 months ago

oauth2-server-grant-type-facebook

Licence
MIT
Version
0.4.0
Deps
0
Size
22 kB
Vulns
0
Weekly
0
Stars
3

OAuth2 Server Facebook Grant Type

Adds Facebook grant type for @node-oauth/oauth2-server

Installation

Using pnpm

pnpm add oauth2-server-grant-type-facebook

Using npm

npm install oauth2-server-grant-type-facebook

Usage

Add getUserWithFacebook to @node-oauth/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 @node-oauth/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
    },
  },
  extendedGrantTypes,
}

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.

Keywords