microauth-twitter

0.1.1 • Public • Published

microauth-twitter

Twitter oauth for micro

Build Status XO code style Greenkeeper badge

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');
const microAuthTwitter = require('microauth-twitter');
 
const options = {
  consumerKey: 'CONSUMER_KEY',
  consumerSecret: 'CONSUMER_SECRET',
  callbackUrl: 'http://localhost:3000/auth/twitter/callback',
  path: '/auth/twitter'
};
 
const twitterAuth = 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
// }}
const handler = async (req, res, auth) => {
 
  if (!auth) {
    return send(res, 404, 'Not Found');
  }
 
  if (auth.err) {
    // Error handler
    return send(res, 403, 'Forbidden');
  }
 
  // save something in database here
 
  return `Hello ${auth.result.info.screen_name}`;
 
};
 
module.exports = twitterAuth(handler);

Run:

micro app.js

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

Author

Dmitry Pavlovsky

Readme

Keywords

none

Package Sidebar

Install

npm i microauth-twitter

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • paloskin