-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9307788
commit 2891b47
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
var OAuth2Strategy = require('../lib/strategy') | ||
, AuthorizationError = require('../lib/errors/authorizationerror') | ||
, chai = require('chai') | ||
, util = require('util'); | ||
|
||
|
||
describe('OAuth2Strategy subclass', function() { | ||
|
||
describe('that overrides tokenParams', function() { | ||
function FooOAuth2Strategy(options, verify) { | ||
OAuth2Strategy.call(this, options, verify); | ||
} | ||
util.inherits(FooOAuth2Strategy, OAuth2Strategy); | ||
|
||
FooOAuth2Strategy.prototype.tokenParams = function(options) { | ||
return { type: options.type }; | ||
} | ||
|
||
describe('subclass that overrides tokenParams function', function() { | ||
var strategy = new FooOAuth2Strategy({ | ||
authorizationURL: 'https://www.example.com/oauth2/authorize', | ||
tokenURL: 'https://www.example.com/oauth2/token', | ||
clientID: 'ABC123', | ||
clientSecret: 'secret', | ||
callbackURL: 'https://www.example.net/auth/example/callback', | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
if (accessToken == '2YotnFZFEjr1zCsicMWpAA' && refreshToken == 'tGzv3JOkF0XG5Qx2TlKWIA') { | ||
return done(null, { id: '1234' }, { message: 'Hello' }); | ||
} | ||
return done(null, false); | ||
}); | ||
|
||
// inject a "mock" oauth2 instance | ||
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) { | ||
if (code == 'SplxlOBeZQQYbYS6WxSbIA' && options.grant_type == 'authorization_code' && options.redirect_uri == 'https://www.example.net/auth/example/callback' && options.type == 'web_server') { | ||
callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { token_type: 'example' }); | ||
} else { | ||
callback(null, 'wrong-access-token', 'wrong-refresh-token'); | ||
} | ||
} | ||
|
||
describe('handling an authorized return request', function() { | ||
var user | ||
, info; | ||
|
||
before(function(done) { | ||
chai.passport.use(strategy) | ||
.success(function(u, i) { | ||
user = u; | ||
info = i; | ||
done(); | ||
}) | ||
.req(function(req) { | ||
req.query = {}; | ||
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA'; | ||
}) | ||
.authenticate({ type: 'web_server' }); | ||
}); | ||
|
||
it('should supply user', function() { | ||
expect(user).to.be.an.object; | ||
expect(user.id).to.equal('1234'); | ||
}); | ||
|
||
it('should supply info', function() { | ||
expect(info).to.be.an.object; | ||
expect(info.message).to.equal('Hello'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |