0.2.0 • Published 5 years ago
@vivvo/passport-citizenone v0.2.0
passport-citizenone
This is the CitizenOne authentication strategy for Passport.js.
Install
$ npm install passport-citizenone
Configuration
Take your credentials from the CitizenOne Tenant Management in your management application and initialize the strategy as follows:
var Strategy = require('passport-citizenone'),
passport = require('passport');
var strategy = new Strategy({
domain: 'your-domain.example.com',
clientID: 'your-client-id',
clientSecret: 'your-client-secret',
callbackURL: '/callback'
},
function(accessToken, refreshToken, extraParams, profile, done) {
// accessToken is the token to call CitizenOne API
// extraParams.id_token has the JSON Web Token
// profile has all the information from the user
return done(null, profile);
}
);
passport.use(strategy);
Usage
app.get('/callback',
passport.authenticate('citizenone', { failureRedirect: '/login' }),
function(req, res) {
if (!req.user) {
throw new Error('user null');
}
res.redirect("/");
}
);
app.get('/login',
passport.authenticate('citizenone', {
scope: 'offline',
state: Math.random().toString(36)
}), function (req, res) {
res.redirect("/");
});
This way when you go to /login
you will get redirected to CitizenOne.
Complete example
A complete example of using this library here.
Related Modules
- passport-oauth2 — used as a base for the passport-citizenone strategy
Tests
$ npm install
$ npm test