Skip to content
JSON Web Token Single Sign-On consumer middleware for Express
JavaScript Makefile
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
test fix tests Sep 29, 2014
.travis.yml Add travis-ci Jul 19, 2013
LICENSE add license Jul 18, 2013
Makefile Add a barebones makefile for (slightly) easier use in the future. Feb 9, 2018 Fix some errors in the example Feb 9, 2018
package.json fix git url Aug 22, 2013

Build Status


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


Setup Express app with jwtsso and session middleware

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

var app = express();

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

    // 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: "", // or /myapp if it lives on sub url

    // Public hostname of your application. This is read from a Host header
    // Use this to override it.
    // host: "application.example",

    // Scheme. "http" or "https". This is read from a "X-Scheme" header.
    // Defaults to "http". Use this to override it.
    // scheme: "http",

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

    // Hook function call after login
    hook: function(token, done) {
        console.log("got token", token);


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();

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


From there authentication endpoint is expected to redirect user back to url specified in the return_to query value with the 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 originally designed for Opinsys SSO

You can’t perform that action at this time.