From 5d66cea96a5baa4037dc7726b6cfbe07637fe179 Mon Sep 17 00:00:00 2001 From: nrhope Date: Tue, 24 Feb 2015 18:27:36 +1100 Subject: [PATCH] protocol/OpenID.js works against master --- config/passport.js | 14 +++++++------- protocols/OpenID.js | 33 +++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/config/passport.js b/config/passport.js index d296ff92..f6a4b6b2 100644 --- a/config/passport.js +++ b/config/passport.js @@ -8,7 +8,7 @@ var _ = require('lodash') , path = require('path') , util = require('util') , config = require(path.join(cwd, 'config.' + env + '.json')) - , providers = require('../providers') + , providers = require('../lib/providers') , LocalStrategy = require('passport-local').Strategy , base64url = require('base64url') , User = require('../models/User') @@ -59,14 +59,14 @@ module.exports = function (passport) { if (config.providers) { Object.keys(config.providers).forEach(function (name) { - var provider = providers[name] - , client = config.providers[name] - , protocol = (provider && provider.protocol) - || (client && client.protocol) - , strategy = require('../protocols/' + protocol) + var providerConf = config.providers[name] + , provider = ( providers[name] ? providers[name] : providerConf ) + , protocol = provider.protocol + , strategy = require('../lib/protocol/' + protocol) ; - passport.use(strategy.initialize(provider, client)); + provider.id = name; + passport.use(strategy.initialize(provider, providerConf)); }); } diff --git a/protocols/OpenID.js b/protocols/OpenID.js index 597ed5f0..57ca7e8d 100644 --- a/protocols/OpenID.js +++ b/protocols/OpenID.js @@ -3,10 +3,31 @@ */ var passport = require('passport') - , OpenIDStrategy = require('passport-openid') + , Strategy = require('passport-openid').Strategy + , util = require('util') , User = require('../../models/User') ; +/** + * OpenIDStrategy + * + * Provider is an object defining the details of the authentication API. + * Client is an object containing provider registration info and options. + * Verify is the Passport callback to invoke after authenticating + */ + +function OpenIDStrategy (provider, verify) { + this.provider = provider; + this.name = provider.id; + if (! provider.returnURL) { + provider.returnURL = provider.callbackURL; + } + Strategy.call(this, provider, verify); + this.client = provider; + this.verify = verify; +} + +util.inherits(OpenIDStrategy, Strategy); /** * Verifier @@ -16,8 +37,8 @@ function verifier (req, identifier, userInfo, done) { // Raw OpenID Provider response should be stored // for consistency with other protocols. var auth = { - // identifier? - // req.query? + id: request.query['openid.identity'], + req_query: req.query }; userInfo.id = request.query['openid.identity']; @@ -36,14 +57,10 @@ OpenIDStrategy.verifier = verifier; /** - * Initialize + * Initialize - note provider === configuration */ function initialize (provider, configuration) { - // provider may be null with this strategy? - // possibly merge with configuration if it's - // an object? - configuration.profile = true; configuration.passReqToCallback = true;