@meotimdihia/fastify-oauth2

2.0.1 • Public • Published

fastify-oauth2

Wrap around simple-oauth2 library.

Install

npm i --save fastify-oauth2

Usage

const fastify = require('fastify')({ logger: { level: 'trace' } })
const oauthPlugin = require('fastify-oauth2')


fastify.register(oauthPlugin, {
  name: 'facebookOAuth2',
  credentials: {
    client: {
      id: '<CLIENT_ID>',
      secret: '<CLIENT_SECRET>'
    },
    auth: oauthPlugin.FACEBOOK_CONFIGURATION
  },
  // register a fastify url to start the redirect flow
  startRedirectPath: '/login/facebook',
  // facebook redirect here after the user login
  callbackUri: 'http://localhost:3000/login/facebook/callback'
})

fastify.get('/login/facebook/callback', async function (request, reply) {
  const result = await this.getAccessTokenFromAuthorizationCodeFlow(request)

  console.log(result.access_token)

  reply.send({ access_token: result.access_token })
})

Example

See facebook example for an example.

Reference

This fastify plugin decorates the fastify instance with the simple-oauth2 instance.

License

Licensed under MIT.

NB: See simple-oauth2 license too

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.11
2.0.015

Package Sidebar

Install

npm i @meotimdihia/fastify-oauth2

Weekly Downloads

16

Version

2.0.1

License

MIT

Unpacked Size

150 kB

Total Files

9

Last publish

Collaborators

  • meotimdihia