0.0.3 • Published 6 years ago

microauth-linkedin v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

microauth-linkedin

linkedin oauth for micro

Installation

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

Usage

app.js

const { send } = require('micro');
const microAuthLinkedin = require('microauth-linkedin');

const options = {
  clientId: 'CLIENT_ID',
  clientSecret: 'CLIENT_SECRET',
  callbackUrl: 'http://localhost:3000/auth-linkedin',
  path: '/auth/linkedin',
  scope: 'r_basicprofile r_emailaddress'
};

const linkedinAuth = microAuthLinkedin(options);

// third `auth` argument will provide error or result of authentication
// so it will { err: errorObject } or { result: {
//  provider: 'linkedin',
//  accessToken: 'blahblah',
//  info: userInfo
// }}
module.exports = linkedinAuth(async (req, res, auth) => {
  if (!auth) {
    return send(res, 404, 'Not Found');
  }

  if (auth.err) {
    // Error handler
    console.error(auth.err);
    return send(res, 403, 'Forbidden');
  }

  return `Hello ${auth.result.info.firstName} ${auth.result.info.lastName} `;

});

Run:

micro app.js

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

Author

Ajay Charotariya