npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

user-management-system

v0.5.2

Published

user management system for vigour projects

Downloads

4

Readme

user-management-system

User Management System(UMS) for vigour projects

  • Launches an express server to manage authentication
  • uses passport and the following strategies:
  • [![Github Stars][passport-facebook-image] passport-facebook][passport-facebook-url] A file system-based session store. [passport-facebook-url]: https://www.npmjs.com/package/passport-facebook [passport-facebook-image]: https://img.shields.io/github/stars/jaredhanson/passport-facebook.svg?label=%E2%98%85
  • if you wish to use another passport strategy, please let me know or implement it yourself and make a pull request
  • Session managed with: [![Github Stars][express-session-image] express-session][express-session-url] using one of the following session stores: [express-session-url]: https://www.npmjs.com/package/session [express-session-image]: https://img.shields.io/github/stars/expressjs/session.svg?label=%E2%98%85
  • [![Github Stars][session-file-store-image] session-file-store][session-file-store-url] A file system-based session store. [session-file-store-url]: https://www.npmjs.com/package/session-file-store [session-file-store-image]: https://img.shields.io/github/stars/valery-barysok/session-file-store.svg?label=%E2%98%85
  • [![Github Stars][connect-redis-image] connect-redis][connect-redis-url] A Redis-based session store. [connect-redis-url]: https://www.npmjs.com/package/connect-redis [connect-redis-image]: https://img.shields.io/github/stars/tj/connect-redis.svg?label=%E2%98%85
  • if you wish to use another session store, please let me know or implement it yourself and make a pull request

Usage:

$ npm install user-management-system
var ums = require('user-management-system')
var config = require('./config.json')

ums.start(config)
  .then((server) ==> console.log('UMS running on port', server.port))
  .catch((err) => log.error('USM', err))

Config:

this is what a typical config should look like:

{
  "port": 9000,
  "session": {
    "options": {},
    "store": {
      "type": "file",
      "options": {}
    }
  },
  "auth": {
    "facebook": {
      "clientID": "FACEBOOK_APP_ID",
      "clientSecret": "FACEBOOK_APP_SECRET",
      "profileFields": ["id", "emails", "gender", "link", "locale", "name", "timezone", "updated_time", "verified"],
      "scope": ["email"]
    }
  }
}
  • port - the port on which the UMS express server will be running (defaults to 9000)
  • session - information about the session management (optional)
  • options - see session options
    • defaults to: { secret: 'my-little-pony', resave: true, saveUninitialized: true }
    • note: you can override the "store" option at your own risk
  • store - choice of predefined session stores
    • type - type of store to use (defaults to "file"), can be:
      • file - use session-file-store
        • default options: { path: "/<tmpdir>/.ums-sessions", logFn: function(){} }
      • redis - use connect-redis
        • default options: { uri: "localhost", port: 6379 }
  • auth - settings for each of the Strategies being used
  • note: no need to specify callback urls
  • note: you should specify the "scope" property here

Advanced usage

checkout the example folder to see a real world implementation using mongodb to store users and sessions
you can run the example simply with $ npm start
note: you need a mongodb server running on the default port(27017)

User management:

out of the box, UMS uses the following function for serializing and deserializing users:

function(user, done){ 
  done(null, user)
 }

and the following verify callback:

//example for the facebook strategy 
function (token, rToken, profile, done){
  var user = {
    strategy: 'facebook',
    profile: profile._json
  }
  user.facebook.token = token
  if(server.config.auth.verifyCallback){
    server.config.auth.verifyCallback(user, done)
  } else {
    done(null, user)
  }
}

and req.user will be an object, looking like:

{ 
  facebook: { 
    id: '10153112773881034',
    email: '[email protected]',
    gender: 'male',
    link: 'https://www.facebook.com/app_scoped_user_id/10153112773881034/',
    locale: 'en_US',
    last_name: 'Padez',
    first_name: 'André',
    middle_name: 'Alçada',
    timezone: 1,
    updated_time: '2015-10-28T10:29:39+0000',
    verified: true,
    token: '<oauth_token>' 
  } 
}

you can, however, override those by setting them to the config object, so:

var ums = require('user-management-system')
var config = require('./config.json')

config.auth.verifyCallback = function(user, done){
db.findUser({'profile.id': user.profile.id}, function(err, userFromDB){
  if(err){
    return done(err)
  }
  if(userFromDb){
    return done(null, userFromDb)
  }
  //if no user in db
  var newUser = new User(user)
  newUser.save(function(err){
    return done(err, newUser)
  })
})
}

config.auth.serializeUser = function(user, done) {
 done(null, user.id)
}

config.auth.deserializeUser = function(id, done){
 db.findUser({id: id}, function(err, user) {
   done(err, user);
 })
}

ums.start(config)
 .then((server) ==> console.log('UMS running on port', server.port))
 .catch((err) => log.error('USM', err))

note: all db operations are fictitious here, just to illustrate