Skip to content
Browse files

Pass extra info argument through to Passport and req.authInfo.

  • Loading branch information...
1 parent 268860c commit 8cac4ca92b697f03127f3f5e4fcc0cc016b367bf @jaredhanson committed Jul 10, 2012
Showing with 40 additions and 2 deletions.
  1. +2 −2 lib/passport-http-bearer/strategy.js
  2. +38 −0 test/strategy-test.js
View
4 lib/passport-http-bearer/strategy.js
@@ -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);
});
}
View
38 test/strategy-test.js
@@ -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) {

0 comments on commit 8cac4ca

Please sign in to comment.
Something went wrong with that request. Please try again.