@cervval/tpfmc-sso
DSI SSO Authentication
Last updated 6 months ago by cervval .
ISC · Original npm · Tarball · package.json
$ cnpm install @cervval/tpfmc-sso 
SYNC missed versions from official npm registry.

This module wraps DSI's specific SSO authentication for a Node.JS Express application.

This is not a general purpose SSO client.

Usage Example:

import * as express from "express";
import * as session from "express-session";
import * as tpfmcSSO from "@cervval/tpfmc-sso";

// Consts
let cookieName = "apppName";
let sessionSecret = 'a secret';//replace with a new generated key for each application
let httpPort = process.env.PORT || 8080;
tpfmcSSO.SETTINGS.ssoUrl = "url to sso server"
tpfmcSSO.SETTINGS.clientId = "client id";
tpfmcSSO.SETTINGS.clientSecret = "client secret";
tpfmcSSO.SETTINGS.publicPaths = ["/public"];

// Init HTTP Server
let expressApp: express.Express = express();

// Sessions
expressApp.use(session({
    secret: sessionSecret,
    name: cookieName + "_" + httpPort + "_sessionId",
    resave: false,
    saveUninitialized: true
}));

// Install authentication
expressApp.use(tpfmcSSO.authenticate);

// Create HTTP Server
expressApp.listen(httpPort, () => {
    let url = "http://localhost:" + httpPort + tpfmcSSO.SETTINGS.rootUrl;
    console.info("HTTP server listening on %s in %s mode", url, expressApp.get('env'));
});

// SSO routes
tpfmcSSO.registerLandingAndLogoutRoutes(expressApp);

// Get User Data route - authenticated
expressApp.post("/getUserInfos", (req, res) => {
    let user = tpfmcSSO.getLoggedInUser(req);
    res.json(user);
});

// Private - authenticated
expressApp.get("/", (req, res) => {
    let user = tpfmcSSO.getLoggedInUser(req);
    res.send("Hello " + user.fullName + "!");
});

// Public - not authenticated (because in SETTINGS.publicPaths)
expressApp.get("/public", (req, res) => {
    res.send("Hello World!")
});

Current Tags

  • 1.0.3                                ...           latest (6 months ago)

2 Versions

  • 1.0.3                                ...           6 months ago
  • 1.0.1                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |