Navigation Menu

Skip to content

Commit

Permalink
Pass extra info argument through to Passport and req.authInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jul 10, 2012
1 parent 268860c commit 8cac4ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/passport-http-bearer/strategy.js
Expand Up @@ -100,10 +100,10 @@ Strategy.prototype.authenticate = function(req) {
if (!token) { return this.fail(this._challenge()); }

var self = this;
this._verify(token, function(err, user) {
this._verify(token, function(err, user, info) {
if (err) { return self.error(err); }
if (!user) { return self.fail(self._challenge('invalid_token')); }
self.success(user);
self.success(user, info);
});
}

Expand Down
38 changes: 38 additions & 0 deletions test/strategy-test.js
Expand Up @@ -122,6 +122,44 @@ vows.describe('BearerStrategy').addBatch({
},
},

'strategy handling a valid request and passing additional info': {
topic: function() {
var strategy = new BearerStrategy(function(token, done) {
done(null, { token: token }, { scope: 'email' });
});
return strategy;
},

'after augmenting with actions': {
topic: function(strategy) {
var self = this;
var req = {};
strategy.success = function(user, info) {
self.callback(null, user, info);
}
strategy.fail = function() {
self.callback(new Error('should not be called'));
}

req.headers = {};
req.headers.authorization = 'Bearer vF9dft4qmT';
process.nextTick(function () {
strategy.authenticate(req);
});
},

'should not generate an error' : function(err, user) {
assert.isNull(err);
},
'should authenticate' : function(err, user) {
assert.equal(user.token, 'vF9dft4qmT');
},
'should pass auth info' : function(err, user, info) {
assert.equal(info.scope, 'email');
}
},
},

'strategy handling a request that is not validated': {
topic: function() {
var strategy = new BearerStrategy(function(token, done) {
Expand Down

0 comments on commit 8cac4ca

Please sign in to comment.