Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jwtsso

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwtsso

JSON Web Token Single Sign-On consumer middleware for Express

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

jwtsso

JSON Web Token Single Sign-On consumer middleware for Express.

Usage

Setup Express app with jwtsso and session middleware

var express = require("express");
var jwtsso = require("jwtsso");

var app = express();

app.use(express.cookieParser());
app.use(express.cookieSession({ secret: "secret" }));
app.use(jwtsso({

    // Service endpoint that issues the jwt tokens
    authEndpoint: "https://api.authprovider.example/sso",

    // Shared secret string with the above service
    sharedSecret: "secret",

    // Public mountpoint for this app
    mountPoint: "http://application.example",

    // Set max age in seconds for the tokens
    // Defaults to 60 seconds
    maxAge: 120

}));

Now from any route or latter middleware you can call res.requestJwt() to get a JWT token from the authEndpoint. The token will be saved to req.session.jwt.

For example to ensure that JWT token is always present you can add following additional middleware

app.use(function(req, res, next){
    if (!req.session.jwt) return res.requestJwt();
    next();
});

By default res.requestJwt([custom path]) will redirect back to same url where it was called from or you can pass in a custom path.

Authentication endpoint

Under the hood call to res.requestJwt() on /current/path redirects user to

https://api.authprovider.example/sso?return_to=http%3A%2F%2Fapplication.example%2Fcurrent/path

From there authentication endpoint is expected to redirect user back to url specified in the return_to query value with the JWT token

http://application.example/current/path?jwt=<token>

jwtsso then detects JWT token in the query string, validates it, sets it to req.session.jwt and clears it from the url bar with an additional redirect.

This module was designed for the Single Sign-On feature of puavo-rest

https://github.com/opinsys/puavo-users/blob/master/rest/doc/SSO.md

Keywords

FAQs

Package last updated on 22 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc