This package has been deprecated

Author message:

deprecated

devmtn-auth

1.0.3 • Public • Published

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('/');
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

Package Sidebar

Install

npm i devmtn-auth

Weekly Downloads

1

Version

1.0.3

License

none

Unpacked Size

17.2 kB

Total Files

9

Last publish

Collaborators

  • brackcarmony
  • jrobber
  • mciver83
  • zacanger