sso-ui
v1.0.0
Published
An express middleware module for CAS authentication with Single Sign On Universitas Indonesia (SSO-UI)
Downloads
13
Maintainers
Readme
sso-ui
A middleware for express.js to authenticate user through SSO-UI.
Usage
Install through npm (you may have to add sudo
):
npm install --save sso-ui
Then require it in your app:
var SSO = require('sso-ui');
Make an object and middlewares:
var app = require('express')();
var session = require('express-session');
var sso = new SSO({
url: 'http://localhost:3000', //required
session_sso: 'sso_user' // defaults to sso_user
});
app.use(session({
secret: 'supersecretkey',
resave: false,
saveUninitialized: true
}));
app.use(sso.middleware);
Login (or Bounce)
app.get('/login', sso.login, function(req, res) {
res.redirect('/');
});
app.get('/user', sso.login, function(req, res) {
res.json(req.sso_user);
});
Logout
app.get('/logout-sso', sso.logout);
Clear session
app.get('/logout', sso.clear, function(req, res) {
res.redirect('/');
});
Block if not authenticated
app.get('/route/to/critical/data', sso.block, function(req, res) {
res.json({ success: true });
});
Get user after authenticated
var user = req.sso_user; // or whatever your session_sso is set to
if (user) {
console.log(user);
// should be equals to
// if role is mahasiswa:
console.log({
username: user.username,
name: user.name,
role: user.role,
npm: user.npm,
org_code: user.org_code,
faculty: user.faculty,
study_program: user.study_program,
educational_program: user.educational_program
});
// if role is staff:
console.log({
username: user.username,
name: user.name,
role: user.role,
nip: user.nip
});
}
Additional Info
The details of organizational code was taken from ristek/sso.