You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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');constmicroAuthGithub=require('microauth-github');constoptions={clientId: 'CLIENT_ID',clientSecret: 'CLIENT_SECRET',callbackUrl: 'https://localhost:3000/auth/github/callback',path: '/auth/github',scope: 'user'};constgithubAuth=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){returnsend(res,404,'Not Found');}if(auth.err){// Error handlerreturnsend(res,403,'Forbidden');}return`Hello ${auth.result.info.login}`;});
Run:
micro app.js
Now visit https://localhost:3000/auth/github
Alternatives
Also you can see micro-github. This is ready for deploy microservice from @mxstbr