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 twitter 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-twitter
# or
yarn add microauth-twitter
Usage
app.js
const{ send }=require('micro');constmicroAuthTwitter=require('microauth-twitter');constoptions={consumerKey: 'CONSUMER_KEY',consumerSecret: 'CONSUMER_SECRET',callbackUrl: 'https://localhost:3000/auth/twitter/callback',path: '/auth/twitter'};consttwitterAuth=microAuthTwitter(options);// third `auth` argument will provide error or result of authentication// so it will { err: errorObject} or { result: {// provider: 'twitter',// accessToken: 'blahblah',// accessTokenSecret: 'blahblah',// info: userInfo// }}consthandler=async(req,res,auth)=>{if(!auth){returnsend(res,404,'Not Found');}if(auth.err){// Error handlerreturnsend(res,403,'Forbidden');}// save something in database herereturn`Hello ${auth.result.info.screen_name}`;};module.exports=twitterAuth(handler);