devmtn-auth
devmountain.com authentication module using json web tokens
Last updated 10 months ago by stevenisbell .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install devmtn-auth 
SYNC missed versions from official npm registry.

DEPRECATED

This authentication service should be considered deprecated. Existing applications will continue to work, all new applications should utilize the DevMountain Single-Sign-On Service.

Contact a member of the development team for details.

DevMountain Auth

With Passport & JSON Web Tokens

This module is a Passport strategy to allow for DevMountain microservice authentication with relatively little configuration. You get all the normal benefits of Passport, including auth redirect/callback, req.user and req.logout, and serializing the user onto the session. Successful authentication will provide a user object with email, user roles, and the unique id from the authentication server database. If your app needs different/more information, it must be configured on DevMountain's app.

Example/recommended server setup here.

Testing: npm test.

Usage

  • Install devmtn-auth: npm i -S devmtn-auth

  • Add devmtnAuthConfig.js to your .gitignore

  • touch a devmtnAuthConfig.js and set it up like this (you provide specific values):

    module.exports = { app : 'app-name' , client_token : 'client-token' , callbackURL : 'callbackURL' , jwtSecret : 'jwtSecret' }

That's it for setup! However, for this to work, your app must be configured on the authentication server, and you must be given appropriate configuration values.


The token can be accessed in the verification callback when you set up the strategy.

passport.use('devmtn', new DevmtnStrategy(devmtnAuthConfig, function(jwtoken, user, done){
  // could attach the token to the session for use against DevMountain APIs
  req.session.jwtoken = jwtoken
  User.findOrCreate({email: user.email}, function(err, local_user){
    return done(err, local_user)
  })
}))

For convenience, devmtn-auth exposes a checkRoles function that can be used to verify user roles from the decoded JSON web token.

var Devmtn = require('devmtn-auth')
Devmtn.checkRoles(req.user, 'student')
// returns bool

devmtn-auth also has an optional 'clearJwtAuthCookie' middleware function to clear the auth cookie that is used for SSO.

var Devmtn = require('devmtn-auth')

app.get('/logout', Devmtn.clearJwtAuthCookie, (req, res, next) => {
  req.logout();
  res.redirect('/');
})

Current Tags

  • 1.0.3                                ...           latest (10 months ago)

9 Versions

  • 1.0.3                                ...           10 months ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 9
Dependencies (5)
Dev Dependencies (7)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |