Skip to content

Rainbow-CPaaS/passport-rainbow-oauth2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Passport strategy for Rainbow OAuth 2.0

Passport strategies for authenticating with Rainbow using ONLY OAuth 2.0.

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

Install

$ npm install passport-rainbow-oauth2

Usage of OAuth 2.0

Configure Strategy

The Rainbow OAuth 2.0 authentication strategy authenticates users using a Rainbow 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 a client ID, client secret, and callback URL. The rainbowDomain strategy allows to specify an alternative Rainbow platform (i.e. : sandbox.openrainbow.com )

var RainbowStrategy = require( 'passport-rainbow-oauth2' ).Strategy;

passport.use(new RainbowStrategy({
    clientID:     RAINBOW_APP_ID,
    clientSecret: RAINBOW_APP_SECRET,
    callbackURL: "http://yourdomain:3000/auth/rainbow/callback",
    passReqToCallback   : true
  },
  function(request, accessToken, refreshToken, profile, done) {
    User.findOrCreate({ rainbowId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

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

For example, as route middleware in an Express application:

app.get('/auth/rainbow',
  passport.authenticate('rainbow', { scope:
  	[ 'email', 'profile' ] }
));

app.get( '/auth/rainbow/callback',
	passport.authenticate( 'rainbow', {
		successRedirect: '/auth/rainbow/success',
		failureRedirect: '/auth/rainbow/failure'
}));

What you will get in profile response ?

   provider         always set to `rainbow`
   id
   name             {givenName, familyName, middleName}
   family_name
   given_name
   displayName
   language
   email
   emails
   phone_number
   phone_numbers
   photos
   picture
   update_at
   zoneinfo

Examples

For a complete, working example, refer to the OAuth 2.0 example.

Credits

License

The MIT License

Copyright (c) 2012-2019 Jared Hanson <http://jaredhanson.net/>

About

Rainbow authentication strategy for Passport and Node.js.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published