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

ssomg

v1.1.19

Published

NPM Client for the SSOMG project

Downloads

37

Readme

SSOMG

This is the node client for the SSOMG single sign on project, designed to work with Express.

Setup

Add this package with the cli command

npm install --save ssomg

and require it in your root index.js file with

ssomg = require('ssomg');

and connect it to your express app like this

var app = express();
app.use(cookieParser()); // req.cookies must be set for sessions to work
ssomg.mount( app );

and then using the route protection middleware, limit route access to specific user roles.

var { protect } = require("ssomg")

router.use( protect("Read") );

or

var { protect } = require("ssomg")

router.get("/example", protect("Admin"), routeHandler )
router.get("/example2", protect(["Admin", "Read", "App Role 2"]), routeHandler )

Protect can either take a string or an array, depending on the number of roles you wish to authorise the route for.

Environment

When you register the app and the users in the main SSOMG admin, you'll be issued with an app id the public key used to verify tokens. You'll need to add the following attributes to your environment file to make sure it works correctly:

PUB_KEY_PATH=./keys/sso
APP_ID=xxxxxxxxxxxxxxxxxxxxxxxx
SSO_HOST=https://auth.mysite.com
NODE_ENV=production (this ensures secure cookies are used)

Using a .env file and with the npm package dotenv or docker is recommended. Set this up quickly by running npm install --save dotenv in the terminal, and require('dotenv').config() at the top of your app entrypoint.

Gotchas

Make sure the mount is after cookies are enabled Make sure the URLs in the env file and the provider app contain the correct protocol(http(s)), and ports. Without the correct protocols, the app will behave unexpectedly.

Details and customisation

Protect can accept an optional set of arguments to define what happens if the user is logged in but does not have permission: { failure_redirect: "The url to redirect to if failure occurs", failure_flash: "A flash message to set if failure occurs. Must have a req.flash() function present", failure_callback: function( req, res, next ) { /** This is a middleware function that is called when the user fails to authorize for a route. Supercedes failure_redirect and failure_flash */ } }

If a user JWT is set, req.user will be set like this:

"req.user": {
  "_id": "xxxxx",
  "first_name": "First",
  "last_name": "Last",
  "email": "[email protected]",
  "roles": [
    "App Role 1",
    "App Role 2"
  ],
  "refresh_token": "xxxxxxxxx",
  "iat": xxxxxxxxxx,
  "exp": xxxxxxxxxx
}

Who do I talk to?

If there's a problem, open an issue or talk to Henry.