passport-keylead

0.1.3 • Public • Published

passport-keylead

Passport strategy for authenticating with Keylead using the OAuth 2.0 API.

This module lets you authenticate using Keylead in your Node.js applications. By plugging into Passport, Keylead authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-keylead

Usage

Configure Strategy

The Keylead authentication strategy authenticates users using a ABPlus account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying an app ID, app secret, callback URL.

passport.use(new KeyleadStrategy({
    clientID: KEYLEAD_APP_ID,
    clientSecret: KEYLEAD_APP_SECRET,
    scope: "adanalas:user:get",
    callbackURL: "http://localhost:3000/auth/keylead/callback"
  },
  function(accessToken, profile, done) {
    User.findOrCreate({ keyleadId: profile.nationalId }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'keylead' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/keylead',
  passport.authenticate('keylead'));

app.get('/auth/keylead/callback',
  passport.authenticate('keylead', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Examples

For a complete, working example, refer to the login example.

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Copyright (c) 2015 Alireza Alidoust

/passport-keylead/

    Package Sidebar

    Install

    npm i passport-keylead

    Weekly Downloads

    0

    Version

    0.1.3

    License

    none

    Last publish

    Collaborators

    • alidoust