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

Fix inconsistent cross origin error handling #667

Merged
merged 2 commits into from
Feb 15, 2018
Merged
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: 2 additions & 1 deletion src/web-auth/cross-origin-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var windowHelper = require('../helper/window');
var objectHelper = require('../helper/object');
var RequestBuilder = require('../helper/request-builder');
var WebMessageHandler = require('./web-message-handler');
var responseHandler = require('../helper/response-handler');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what convention are you following by using a lowercase for the first letter and a capital one for the WebMessageHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebMessageHandler is a class, responseHandler is a function


function CrossOriginAuthentication(webAuth, options) {
this.webAuth = webAuth;
Expand Down Expand Up @@ -70,7 +71,7 @@ CrossOriginAuthentication.prototype.login = function(options, cb) {
error: 'request_error',
error_description: JSON.stringify(err)
};
return cb(errorObject);
return responseHandler(cb)(errorObject);
}
var popupMode = options.popup === true;
options = objectHelper.blacklist(options, ['password', 'credentialType', 'otp', 'popup']);
Expand Down
16 changes: 12 additions & 4 deletions test/web-auth/cross-origin-authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
response: {
body: {
error: 'any_error',
error_description: 'any error'
error_description: 'a super big error message description'
}
}
});
Expand All @@ -267,7 +267,11 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
anotherOption: 'foobar'
},
function(err) {
expect(err).to.be.eql({ error: 'any_error', error_description: 'any error' });
expect(err).to.be.eql({
original: { error: 'any_error', error_description: 'a super big error message description' },
code: 'any_error',
description: 'a super big error message description'
});
expect(_this.webAuthSpy.authorize.called).to.be.eql(false);
done();
}
Expand Down Expand Up @@ -300,8 +304,12 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
},
function(err) {
expect(err).to.be.eql({
error: 'request_error',
error_description: '{"some":"error"}'
original: {
error: 'request_error',
error_description: '{"some":"error"}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this particular error description is an object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a string, not an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
code: 'request_error',
description: '{"some":"error"}'
});
expect(_this.webAuthSpy.authorize.called).to.be.eql(false);
done();
Expand Down