The project goal is to provide simple SSO in node.js.
-
get nodeSSO:
npm install nodeSSOor
git clone [email protected]:adrai/nodeSSO.git -
go to /example
-
run
npm install express,npm install everyauth -
start the app
node server.js -
direct your browser to localhost:3001
Using nodeSSO comes very easy to use with everyauth and express.
-
Create a sso juggler
var SsoJuggler = require('nodeSSO'); var ssoJuggler = new SsoJuggler({ authenticationPath: '/auth/openid?openid_identifier=https://www.google.com/accounts/o8/id' }); -
use everyauth
var everyauth = require('everyauth'); everyauth .openid .myHostname('http://localhost:3001') .findOrCreateUser( function (session, userMetadata) { // Don't forget to save the userIdentifier! ssoJuggler.saveUserIdentifier(session, userMetadata.email); return userMetadata; }) .redirectPath(successPath); -
use express
var express = require('express'); var app = express.createServer( express.bodyParser() , express.static(__dirname + "/public") , express.cookieParser() , express.session({ secret: 'htuayreve' }) , everyauth.middleware() ); everyauth.helpExpress(app); -
add routes
ssoJuggler.addRoutes(app); -
and run the service
app.listen(3001); -
now you can authenticate calling: "http://localhost:3001/auth?callbackUrl=http://www.google.ch" and deauthenticat calling: "http://localhost:3001/deauth?callbackUrl=http://www.google.ch"
-
after a successfull authentication you will receive the userIdentifier with the parameter userIdentifier