Permalink
Browse files

Merge pull request #3 from ancasicolica/master

Express 4
  • Loading branch information...
2 parents af48221 + bfb8f22 commit 7f5f896239832020555f5baadf7b2f18af1c82e5 @gbraad committed Jun 9, 2016
Showing with 158 additions and 161 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 .travis.yml
  3. +31 −57 app.js
  4. +16 −15 config/config.js
  5. +26 −25 config/passport.js
  6. +58 −55 config/routes.js
  7. +24 −8 package.json
View
@@ -1,3 +1,4 @@
/node_modules
/bower_components
/public
+/.idea
View
@@ -1,6 +1,7 @@
language: node_js
node_js:
- - "0.10"
+ - "4"
+ - "6"
before_install:
- npm install -g npm
View
@@ -1,67 +1,41 @@
-var express = require('express'),
- http = require('http'),
- path = require('path'),
- passport = require("passport");
+const express = require('express');
+const http = require('http');
+const path = require('path');
+const passport = require('passport');
+const morgan = require('morgan');
+const cookieParser = require('cookie-parser');
+const bodyParser = require('body-parser');
+const session = require('express-session');
+const errorhandler = require('errorhandler');
-var env = process.env.NODE_ENV || 'development',
- config = require('./config/config')[env];
+var env = process.env.NODE_ENV || 'development';
+const config = require('./config/config')[env];
-require('./config/passport')(passport, config);
+console.log('Using configuration', config);
+require('./config/passport')(passport, config);
var app = express();
-app.configure(function () {
- app.set('port', config.app.port);
- app.set('views', __dirname + '/app/views');
- app.set('view engine', 'jade');
- app.use(express.logger('dev'));
- app.use(express.cookieParser());
- app.use(express.bodyParser());
- app.use(express.session(
- {
- secret: 'this shit hits'
- }));
- app.use(passport.initialize());
- app.use(passport.session());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(path.join(__dirname, 'public')));
-});
-
-app.configure('development', function () {
- console.log ("Development mode.");
- app.use(express.errorHandler());
-});
-app.configure ('production', function () {
- console.log ("Production mode.");
-});
-
-app.use(function(err, req, res, next) {
- res.status(err.status || 500);
- res.render('500', { error: err });
-});
-
-app.use(function(req, res, next){
- res.status(404);
- if (req.accepts('html')) {
- res.render('404',
- {
- url : req.url
- });
- return;
- }
- if (req.accepts('json')) {
- res.send({ error: 'Not found' });
- return;
- }
- res.type('txt').send('Not found');
-});
-
+app.set('port', config.app.port);
+app.set('views', __dirname + '/app/views');
+app.set('view engine', 'jade');
+app.use(morgan('combined'));
+app.use(cookieParser());
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({extended: false}));
+app.use(session(
+ {
+ resave: true,
+ saveUninitialized: true,
+ secret: 'this shit hits'
+ }));
+app.use(passport.initialize());
+app.use(passport.session());
+app.use(express.static(path.join(__dirname, 'public')));
require('./config/routes')(app, config, passport);
-
-http.createServer(app).listen(app.get('port'), function () {
- console.log("Express server listening on port " + app.get('port'));
+app.listen(app.get('port'), function () {
+ console.log('Express server listening on port ' + app.get('port'));
});
View
@@ -1,16 +1,17 @@
module.exports = {
- development : {
- app : {
- name : 'Passport SAML strategy example',
- port : process.env.PORT || 3000
- },
- passport: {
- strategy : 'saml',
- saml : {
- path : '/login/callback',
- entryPoint : 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
- issuer : 'passport-saml'
- }
- }
- }
-}
+ development: {
+ app: {
+ name: 'Passport SAML strategy example',
+ port: process.env.PORT || 3000
+ },
+ passport: {
+ strategy: 'saml',
+ saml: {
+ path: process.env.SAML_PATH || '/login/callback',
+ entryPoint: process.env.SAML_ENTRY_POINT || 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
+ issuer: 'passport-saml',
+ cert: process.env.SAML_CERT || null
+ }
+ }
+ }
+};
View
@@ -1,31 +1,32 @@
-var SamlStrategy = require('passport-saml').Strategy
+const SamlStrategy = require('passport-saml').Strategy;
module.exports = function (passport, config) {
- passport.serializeUser(function(user, done) {
- done(null, user);
- });
+ passport.serializeUser(function (user, done) {
+ done(null, user);
+ });
- passport.deserializeUser(function(user, done) {
- done(null, user);
- });
+ passport.deserializeUser(function (user, done) {
+ done(null, user);
+ });
- passport.use(new SamlStrategy(
- {
- path: config.passport.saml.path,
- entryPoint: config.passport.saml.entryPoint,
- issuer: config.passport.saml.issuer
- },
- function(profile, done) {
- return done(null,
- {
- id : profile.uid,
- email : profile.email,
- displayName : profile.cn,
- firstName : profile.givenName,
- lastName : profile.sn
- });
- })
- );
+ passport.use(new SamlStrategy(
+ {
+ path: config.passport.saml.path,
+ entryPoint: config.passport.saml.entryPoint,
+ issuer: config.passport.saml.issuer,
+ cert: config.passport.saml.cert
+ },
+ function (profile, done) {
+ return done(null,
+ {
+ id: profile.uid,
+ email: profile.email,
+ displayName: profile.cn,
+ firstName: profile.givenName,
+ lastName: profile.sn
+ });
+ })
+ );
-}
+};
View
@@ -1,55 +1,58 @@
-module.exports = function(app, config, passport) {
- app.get("/", function(req, res) {
- if(req.isAuthenticated()) {
- res.render("home",
- {
- user : req.user
- });
- } else {
- res.render("home",
- {
- user : null
- });
- }
- });
-
- app.get("/login",
- passport.authenticate(config.passport.strategy,
- {
- successRedirect : "/",
- failureRedirect : "/login",
- })
- );
-
- app.post('/login/callback',
- passport.authenticate(config.passport.strategy,
- {
- failureRedirect: '/',
- failureFlash: true
- }),
- function(req, res) {
- res.redirect('/');
- }
- );
-
- app.get("/signup", function (req, res) {
- res.render("signup");
- });
-
- app.get("/profile", function(req, res) {
- if(req.isAuthenticated()){
- res.render("profile",
- {
- user : req.user
- });
- } else {
- res.redirect("/login");
- }
- });
-
- app.get('/logout', function(req, res) {
- req.logout();
- // TODO: invalidate session on IP
- res.redirect('/');
- });
-}
+
+module.exports = function (app, config, passport) {
+
+ app.get('/', function (req, res) {
+ if (req.isAuthenticated()) {
+ res.render('home',
+ {
+ user: req.user
+ });
+ } else {
+ res.render('home',
+ {
+ user: null
+ });
+ }
+ });
+
+ app.get('/login',
+ passport.authenticate(config.passport.strategy,
+ {
+ successRedirect: '/',
+ failureRedirect: '/login'
+ })
+ );
+
+ app.post(config.passport.saml.path,
+ passport.authenticate(config.passport.strategy,
+ {
+ failureRedirect: '/',
+ failureFlash: true
+ }),
+ function (req, res) {
+ res.redirect('/');
+ }
+ );
+
+ app.get('/signup', function (req, res) {
+ res.render('signup');
+ });
+
+ app.get('/profile', function (req, res) {
+ if (req.isAuthenticated()) {
+ res.render('profile',
+ {
+ user: req.user
+ });
+ } else {
+ res.redirect('/login');
+ }
+ });
+
+ app.get('/logout', function (req, res) {
+ req.logout();
+ // TODO: invalidate session on IP
+ res.redirect('/');
+ });
+
+};
View
@@ -7,6 +7,12 @@
"email": "me@gbraad.nl",
"url": "http://gbraad.nl"
},
+ "contributors": [
+ {
+ "name": "Christian Kuster",
+ "email": "git@kusti.ch"
+ }
+ ],
"keywords": [
"saml",
"sso"
@@ -17,16 +23,26 @@
},
"scripts": {
"start": "nodemon app.js",
- "test": ""
+ "test": "",
+ "postinstall": "bower install"
},
"dependencies": {
- "express": "3.1.0",
- "jade": "*",
- "nodemon": "*",
- "passport": "*",
- "passport-saml": "*"
+ "body-parser": "1.15.1",
+ "cookie-parser": "1.4.3",
+ "errorhandler": "1.4.3",
+ "express": "4.13.4",
+ "express-session": "1.13.0",
+ "jade": "1.11.0",
+ "morgan": "1.7.0",
+ "nodemon": "1.9.2",
+ "passport": "0.3.2",
+ "passport-saml": "0.15.0"
+ },
+ "devDependencies": {
+ "bower": "1.7.9"
},
"engines": {
- "node": ">= 0.10.0"
- }
+ "node": ">= 4.0.0"
+ },
+ "license": "MIT"
}

0 comments on commit 7f5f896

Please sign in to comment.