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 Facebook authentication to your micro service as easy as a flick of your fingers.
This module is a part of microauth collection.
Installation
npm install --save microauth-facebook
# or
yarn add microauth-facebook
Usage
app.js
const{ send }=require('micro');constmicroAuthFacebook=require('microauth-facebook');constoptions={appId: 'APP_ID',appSecret: 'APP_SECRET',callbackUrl: 'https://localhost:3000/auth/facebook/callback',path: '/auth/facebook',fields: 'name,email,cover,first_name',// Check fields list here: https://developers.facebook.com/docs/graph-api/reference/v2.11/userscope: 'public_profile,email'// Check permissions list here: https://developers.facebook.com/docs/facebook-login/permissions};constfacebookAuth=microAuthFacebook(options);// third `auth` argument will provide error or result of authentication// so it will { err: errorObject} or { result: {// provider: 'facebook',// accessToken: 'blahblah',// info: userInfo// }}module.exports=facebookAuth(async(req,res,auth)=>{if(!auth){returnsend(res,404,'Not Found');}if(auth.err){// Error handlerconsole.error(auth.err);returnsend(res,403,'Forbidden');}return`Hello ${auth.result.info.first_name}`;});