1.0.10 • Published 7 years ago

googleauth-micro v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

googleauth-micro

Installation

npm install --save googleauth-micro

Usage

app.js

const { send } = require('micro');
const microAuthGoogle = require('googleauth-micro');

const options = {
  clientId: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  callbackUrl: 'http://localhost:3000/oauthCallback',
  path: '/auth/Gplus',
  scope: 'https://www.googleapis.com/auth/plus.me',
  access_type:'offline'
};

const googleAuth = microAuthGoogle(options);

// third `auth` argument will provide error or result of authentication
// so it will { err: errorObject } or { result: {
//  provider: 'google',
//  accessToken: 'blahblah',
//  info: userInfo
// }}
module.exports = googleAuth(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.name}`;

});

Run:

micro app.js

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

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

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