Enable to perform login using oauth2 protocol
Switch branches/tags
Nothing to show
Clone or download
Latest commit e65938f Oct 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add Google login example Oct 28, 2018
.gitignore Ignore package-lock.json Jun 13, 2018
.travis.yml Initial implementation Jun 12, 2018
LICENSE Initial commit Jun 10, 2018
README.md Fix README.md Jul 5, 2018
index.js Add Google configuration Oct 28, 2018
package.json 0.2.2 Oct 28, 2018
test.js Fix error message Oct 28, 2018

README.md

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