passport-jirengu

1.0.1 • Public • Published

passport-jirengu

Install

$ npm install passport-jirengu

Usage

Create an Application

Before using passport-jirengu, you must register an application with Jirengu. If you have not already done so, a new application can be created at developer applications within Jirengu's settings panel. Your application will be issued a client ID and client secret, which need to be provided to the strategy. You will also need to configure a callback URL which matches the route in your application.

Configure Strategy

The Jirengu authentication strategy authenticates users using a Jirengu account and OAuth 2.0 tokens. The client ID and secret obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's Jirengu profile. The verify callback must call cb providing a user to complete authentication.

var JirenguStrategy = require('passport-jirengu').Strategy;
 
passport.use(new JirenguStrategy({
    clientID: JIRENGU_CLIENT_ID,
    clientSecret: JIRENGU_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/jirengu/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ jirenguId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

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

Examples

You can find example at http://note.ruoyu.site

License

The MIT License

Copyright (c) 2011-2016 Jared Hanson <http://jaredhanson.net/>

Readme

Keywords

Package Sidebar

Install

npm i passport-jirengu

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • hunger