Skip to content

Commit

Permalink
Slight tweaks for framework setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 27, 2013
1 parent f639d4c commit 266b72e
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions lib/passport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Passport() {
this._serializers = [];
this._deserializers = [];
this._infoTransformers = [];
this._plugin = null;
this._framework = null;

this._userProperty = 'user';

Expand Down Expand Up @@ -78,6 +78,30 @@ Passport.prototype.unuse = function(name) {
return this;
}

/**
* Setup Passport to be used under framework.
*
* By default, Passport exposes middleware that operate using Connect-style
* middleware using a `fn(req, res, next)` signature. Other popular frameworks
* have different expectations, and this function allows Passport to be adapted
* to operate within such environments.
*
* If you are using a Connect-compatible framework, including Express, there is
* no need to invoke this function.
*
* Examples:
*
* passport.framework(require('hapi-passport')());
*
* @param {Object} name
* @return {Passport} for chaining
* @api public
*/
Passport.prototype.framework = function(fw) {
this._framework = fw;
return this;
}

/**
* Passport's primary initialization middleware.
*
Expand Down Expand Up @@ -105,8 +129,8 @@ Passport.prototype.initialize = function(options) {
options = options || {};
this._userProperty = options.userProperty || 'user';

if (this._plugin && this._plugin.initialize) {
return this._plugin.initialize().bind(this);
if (this._framework && this._framework.initialize) {
return this._framework.initialize().bind(this);
}

return initialize().bind(this);
Expand Down Expand Up @@ -175,8 +199,8 @@ Passport.prototype.session = function() {
* @api public
*/
Passport.prototype.authenticate = function(strategy, options, callback) {
if (this._plugin && this._plugin.authenticate) {
return this._plugin.authenticate(strategy, options, callback).bind(this);
if (this._framework && this._framework.authenticate) {
return this._framework.authenticate(strategy, options, callback).bind(this);
}

return authenticate(strategy, options, callback).bind(this);
Expand Down

0 comments on commit 266b72e

Please sign in to comment.