1.1.0 • Published 8 years ago

cas-client-node v1.1.0

Weekly downloads
64
License
-
Repository
github
Last release
8 years ago

CAS client node

A cas client for nodejs

Installation

npm i cas-client-node --save

Build

npm run build

Example

import express from 'express';
import CAS from 'cas-client-node';
import session from 'express-session';
const port=80;
server=express();
const cas = CAS({
    cas_host: 'https://cas-server.com/cas',
    service: 'http://localhost/sso'
});
server.use(session({
    secret: 'secret',
    resave: false,
    saveUninitialized: true
}))
server.get('/sso', cas.auth, async(req, res, next)=> {
    if (req.user) {
        let expires = new Date();
        expires.setDate(expires.getDate() + 90);
        res.cookie('user', req.user, {expires: expires});
        if (req.headers.referer)
            res.redirect(req.headers.referer);
        else res.redirect('/');
    }
    else {
        res.status(200).send('An error occur when login');
    }
});
server.get('/users/logout', cas.logout, async(req, res, next)=> {
    res.cookie('user', null, {expires: new Date(Date.now() - 1000)});
    res.redirect('/?ref=logout');
});
server.listen(port, () => {   
    console.log(`The server is running at http://localhost:${port}/`);
});

Made with ♥ by hoangrio

1.1.0

8 years ago

1.0.9

8 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago