@alohahealth/micro-bluebutton
v0.1.3
Published
CMS Blue Button 2.0 OAuth for ZEIT Micro
Downloads
9
Readme
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
- Register your application client on the Developer Sandbox
- 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
- Visit
http://localhost:3000/auth/bluebutton
- Enter USERNAME:
BBUser00000
and PASSWORD:PW00000!
- Click the ALLOW button when prompted by Blue Button
- See
Hello Jane Doe
as the response