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

Updated the authentication call to check for the OAuth param for errors #63

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions lib/strategy.js
Original file line number Diff line number Diff line change
@@ -163,8 +163,13 @@ OAuth2Strategy.prototype.authenticate = function(req, options) {

self._oauth2.getOAuthAccessToken(code, params,
function(err, accessToken, refreshToken, params) {
if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err)); }

if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err));}
if (params.error) {
var error = new Object();
error.statusCode = params.error;
error.data = params.error_description;
return self.error(self._createOAuthError('Failed to obtain access token', error));
}
self._loadUserProfile(accessToken, function(err, profile) {
if (err) { return self.error(err); }

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.3.0",
"version": "1.3.1",
"description": "OAuth 2.0 authentication strategy for Passport.",
"keywords": [
"passport",
40 changes: 40 additions & 0 deletions test/oauth2.test.js
Original file line number Diff line number Diff line change
@@ -1168,6 +1168,46 @@ describe('OAuth2Strategy', function() {
expect(err.oauthError.data).to.equal('Something went wrong');
});
}); // that errors due to token request error, in node-oauth object literal form with text body

describe('that errors due to token request error, param object contains errors', function() {
var strategy = new OAuth2Strategy({
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, params, profile, done) {
return done(new Error('verify callback should not be called'));
});

strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
return callback(null, '2YotnFZFEjr1zCsicMWpAA', 'tGzv3JOkF0XG5Qx2TlKWIA', { error: 500, error_description: 'Something went wrong' });
}


var param;

before(function(done) {
chai.passport.use(strategy)
.error(function(e) {
param = e;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA';
})
.authenticate();
});

it('should error', function() {
expect(param).to.be.an.instanceof(InternalOAuthError)
expect(param.message).to.equal('Failed to obtain access token');
expect(param.oauthError.statusCode).to.equal(500);
expect(param.oauthError.data).to.equal('Something went wrong');
});
}); // that errors due to token request error, in node-oauth object literal form with text body

describe('that errors due to verify callback supplying error', function() {
var strategy = new OAuth2Strategy({