googleauth-micro

1.0.10 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i googleauth-micro

Weekly Downloads

0

Version

1.0.10

License

ISC

Last publish

Collaborators

  • acharotariya
  • harsh80016