Skip to content

Repository files navigation

microauth-google

Google oauth for micro

Build StatusXO code styleGreenkeeper badge

Add google authentication to your micro in few lines of code.

Inspired by Dmitry Pavlovskymicroauth-github

Installation

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

Usage

app.js

const{ send }=require('micro');constmicroAuthGoogle=require('microauth-google');constoptions={clientId: 'CLIENT_ID',clientSecret: 'CLIENT_SECRET',callbackUrl: 'http://localhost:3000/auth/google/callback',path: '/auth/google',scope: 'https://www.googleapis.com/auth/plus.me'};constgoogleAuth=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,// client: OAuth2Client instance// }}module.exports=googleAuth(async(req,res,auth)=>{if(!auth){returnsend(res,404,'Not Found');}if(auth.err){// Error handlerreturnsend(res,403,'Forbidden');}return`Hello ${auth.result.info.display_name}`;});

Run:

micro app.js

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

Scopes

String|String[] Scopes define the access list the app needs. It can either be a string or an array of strings. Default scopes and always present are the mandatory from OpenID 2.0:

  • openid
  • email
  • profile

OAuth2Client

OAuth2Client An instance of OAuth2Client is supplied for further use, mainly because this module no longer relies on googleapis nor it has as dependecy.

Author

Rui Pedro Lima

About

Google oauth for micro

Resources

Stars

11 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages