Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to specify a custom agent for OAuth2Strategy via customHeaders #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function OAuth2Strategy(options, verify) {
this._trustProxy = options.proxy;
this._passReqToCallback = options.passReqToCallback;
this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
if(options.customHeaders && options.customHeaders.agent != undefined){
this._oauth2.setAgent(options.customHeaders.agent);
}
}

// Inherit from `passport.Strategy`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-oauth2",
"version": "1.4.0",
"version": "1.4.1",
"description": "OAuth 2.0 authentication strategy for Passport.",
"keywords": [
"passport",
Expand Down
30 changes: 27 additions & 3 deletions test/oauth2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('OAuth2Strategy', function() {
expect(strategy.name).to.equal('oauth2');
});
}); // with normal options

describe('without a verify callback', function() {
it('should throw', function() {
expect(function() {
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('OAuth2Strategy', function() {


describe('processing response to authorization request', function() {

describe('that was approved without redirect URI', function() {
var strategy = new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
Expand Down Expand Up @@ -1705,5 +1705,29 @@ describe('OAuth2Strategy', function() {
}); // processing response to authorization request

}); // using a relative redirect URI


describe('with custom agent in custom headers', function() {
var strategy = new OAuth2Strategy({
authorizationURL: 'https://www.example.com/oauth2/authorize',
tokenURL: 'https://www.example.com/oauth2/token',
clientID: 'ABC123',
clientSecret: 'secret',
callbackURL: '/auth/example/callback',
customHeaders: {
agent: 'Awesome agent'
}
},
function(accessToken, refreshToken, profile, done) {
if (accessToken !== '2YotnFZFEjr1zCsicMWpAA') { return done(new Error('incorrect accessToken argument')); }
if (refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA') { return done(new Error('incorrect refreshToken argument')); }
if (typeof profile !== 'object') { return done(new Error('incorrect profile argument')); }
if (Object.keys(profile).length !== 0) { return done(new Error('incorrect profile argument')); }

return done(null, { id: '1234' }, { message: 'Hello' });
});

it('should set agent in oauth2', function() {
expect(strategy._oauth2._agent).to.equal('Awesome agent');
});
});
});