0.1.3 • Published 5 years ago

@alohahealth/micro-bluebutton v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

micro-bluebutton

BlueButton 2.0 OAuth Client for ZEIT micro

Add CMS BlueButton 2.0 authentication to your micro service in just a few keystrokes.

This module is graciously borrowed from, but not affiliated with the microauth collection.

Installation

npm install --save @alohahealth/micro-bluebutton
# or
yarn add @alohahealth/micro-bluebutton

Usage

  1. Register your application client on the Developer Sandbox
  2. Create the following micro app as app.js:
const { send } = require('micro')
const microBlueButton = require('micro-bluebutton')

const options = {
  dev: process.env.NODE_ENV !== 'production',
  clientId: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  callbackUrl: 'http://localhost:3000/auth/bluebutton/callback',
  path: '/auth/bluebutton',
}

const blueButtonAuth = microBlueButton(options)

// Third `auth` argument will provide error or the results of authentication
// so it will { err: errorObject } or
// { result: {
//     provider: 'bluebutton',
//     token: { /token response object },
//     user: { /userinfo response object },
// }}
const handler = async (req, res, auth) => {
  if (!auth) {
    return send(res, 404, 'Not Found')
  }

  if (auth.err) {
    // Error handler
    console.error(auth.err)
    return send(res, 403, 'Forbidden')
  }

  return `Hello ${auth.result.user.name}`
}

module.exports = blueButtonAuth(handler)

Run:

micro app.js
  1. Visit http://localhost:3000/auth/bluebutton
  2. Enter USERNAME: BBUser00000 and PASSWORD: PW00000!
  3. Click the ALLOW button when prompted by Blue Button
  4. See Hello Jane Doe as the response

Author

Adam Barry