Coder Social home page Coder Social logo

ekojsalim / sso-ui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rkkautsar/sso-ui

0.0 1.0 0.0 25 KB

An express middleware module for CAS authentication with Single Sign On Universitas Indonesia (SSO-UI)

License: MIT License

JavaScript 100.00%

sso-ui's Introduction

sso-ui

npm badge

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.

sso-ui's People

Contributors

rkkautsar avatar ekojsalim avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.