Permalink
Browse files

fixed example to work with express 3.x

  • Loading branch information...
1 parent 30d2110 commit 129b89553e564ec6e3e7c854c0898465cf54fe75 @bachp committed Dec 29, 2013
Showing with 25 additions and 29 deletions.
  1. +25 −29 examples/login/app.js
View
54 examples/login/app.js
@@ -1,18 +1,36 @@
var express = require('express')
+ , http = require('http')
, passport = require('passport')
, util = require('util')
, XingStrategy = require('passport-xing').Strategy;
+var app = express();
+
+// configure Express
+app.set('port', process.env.PORT || 3000);
+app.set('views', __dirname + '/views');
+app.set('view engine', 'ejs');
+app.use(express.logger());
+app.use(express.cookieParser());
+app.use(express.bodyParser());
+app.use(express.methodOverride());
+app.use(express.session({ secret: 'keyboard cat' }));
+// Initialize Passport! Also use passport.session() middleware, to support
+// persistent login sessions (recommended).
+app.use(passport.initialize());
+app.use(passport.session());
+app.use(app.router);
+app.use(express.static(__dirname + '/public'));
+
var XING_API_KEY = "--insert-xing-api-key-here--"
var XING_SECRET_KEY = "--insert-xing-secret-key-here--";
-
// Passport session setup.
// To support persistent login sessions, Passport needs to be able to
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing. However, since this example does not
-// have a database of user records, the complete Linked profile is
+// have a database of user records, the complete Xing profile is
// serialized and deserialized.
passport.serializeUser(function(user, done) {
done(null, user);
@@ -35,7 +53,6 @@ passport.use(new XingStrategy({
function(token, tokenSecret, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
-
// To keep the example simple, the user's Xing profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the Xing account with a user record in your database,
@@ -45,29 +62,6 @@ passport.use(new XingStrategy({
}
));
-
-
-
-var app = express.createServer();
-
-// configure Express
-app.configure(function() {
- app.set('views', __dirname + '/views');
- app.set('view engine', 'ejs');
- app.use(express.logger());
- app.use(express.cookieParser());
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(express.session({ secret: 'keyboard cat' }));
- // Initialize Passport! Also use passport.session() middleware, to support
- // persistent login sessions (recommended).
- app.use(passport.initialize());
- app.use(passport.session());
- app.use(app.router);
- app.use(express.static(__dirname + '/public'));
-});
-
-
app.get('/', function(req, res){
res.render('index', { user: req.user });
});
@@ -97,7 +91,7 @@ app.get('/auth/xing',
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function function will be called,
// which, in this example, will redirect the user to the home page.
-app.get('/auth/xing/callback',
+app.get('/auth/xing/callback',
passport.authenticate('xing', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
@@ -108,7 +102,9 @@ app.get('/logout', function(req, res){
res.redirect('/');
});
-app.listen(3000);
+http.createServer(app).listen(app.get('port'), function(){
+ console.log('Express server listening on port ' + app.get('port'));
+});
// Simple route middleware to ensure user is authenticated.
@@ -118,5 +114,5 @@ app.listen(3000);
// login page.
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
- res.redirect('/login')
+ res.redirect('/login');
}

0 comments on commit 129b895

Please sign in to comment.