@openauth/facebook
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

Open Auth - Facebook

Downloads Version License Typescript dependencies Status

@openauth/facebook is an implementation of Facebook OAuth.

Installation

npm i @openauth/facebook

Usage

import { FacebookOAuth } from '@openauth/facebook'

const oauth = new FacebookOAuth({
  clientId: 'client_id',
  clientSecret: 'client_secret',
  redirectUri: 'https://wani.kr/auth/facebook/callback',
  scope: [
    'public_profile',
  ],
})

OAuth login link.

oauth.getAuthRequestUri() // print https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=client_id&redirect_uri=https%3A%2F%2Fwani.kr%2Fauth%2Ffacebook%2Fcallback&scope=public_profile

After logging in, you will be redirected to the redirectUri page with the code value.

const code = 'AQAO3q3...'

const response = await oauth.getAccessTokenResponse(code)
console.log(response) // { accessToken: 'EAAD...', tokenType: 'bearer', expiresIn: 5165353 }

Save accessToken and use it when requesting API.

const user = await oauth.getAuthUser(response.accessToken)
console.log(user) // { id: '3000000', name: 'Cris Jun' }

Package Sidebar

Install

npm i @openauth/facebook

Weekly Downloads

26

Version

0.4.0

License

MIT

Unpacked Size

11.7 kB

Total Files

15

Last publish

Collaborators

  • wan2land