0.0.4 • Published 7 years ago

microauth-github v0.0.4

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

microauth-gituhb

Github oauth for micro

Build Status XO code style Greenkeeper badge

Add github authentication to your micro in few lines of code. This module is a part of microauth collection.

Installation

npm install --save microauth-github
# or
yarn add microauth-github

Usage

app.js

const { send } = require('micro');
const microAuthGithub = require('./');

const options = {
  clientId: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  callbackUrl: 'http://localhost:3000/auth/github/callback',
  path: '/auth/github',
  scope: 'user'
};

const githubAuth = microAuthGithub(options);

// third `auth` argument will provide error or result of authentication
// so it will { err: errorObject } or { result: {
//  provider: 'github',
//  accessToken: 'blahblah',
//  info: userInfo
// }}
module.exports = githubAuth(async (req, res, auth) => {

  if (!auth) {
    return send(res, 404, 'Not Found');
  }

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

  return `Hello ${auth.result.info.login}`;

});

Run:

micro app.js

Now visit http://localhost:3000/auth/github

Alternatives

Also you can see micro-github. This is ready for deploy microservice from @mxstbr

Author

Dmitry Pavlovsky

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago