1.6.1 • Published 7 years ago

micro-auth2 v1.6.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

This is the oauth 2.0 authentication middleware for Octane zeit micro-services. It checks for accessTokens and checks for the token's status and scope, and also makes the user's ID available inside of a req.userData object.

It expects access tokens to be provided in the Authorization header, prepended with 'Bearer'

Installation

yarn add micro-auth2

Usage

const auth = require('micro-auth2')

module.exports = auth({
    introspectionUrl: '<INTROSPECTION_URL>',
    clientId: '<CLIENT_ID>',
    clientSecret: '<CLIENT_SECRET>'
  })(async (req, res) => {
  return 'Hello World!'
})

Composed with other micro plugins

const auth = require('micro-auth2')
const visualize = require('micro-visualize')
const cookieParse = require('micro-cookie')
const { compose } = require('lodash/fp')
const { send } = require('micro')

module.exports = compose(
  auth({
    introspectionUrl: '<INTROSPECTION_URL>',
    clientId: '<CLIENT_ID>',
    clientSecret: '<CLIENT_SECRET>'
  }),
  visualize,
  cookieParse
)(async (req, res) => {
  const { userId, scope } = req.userData
  const responseMessage = {
    message: 'Great! You have been authenticated!',
    userId,
    scope
  }

  send(res, 200, responseMessage)
})
1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago