Skip to content

Commit

Permalink
Fixing error handling for auth in poopup mode (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge authored Feb 16, 2018
1 parent 63c7486 commit f39ebd5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/web-auth/cross-origin-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CrossOriginAuthentication.prototype.login = function(options, cb) {
var key = createKey(_this.baseOptions.rootUrl, data.body.co_id);
theWindow.sessionStorage[key] = data.body.co_verifier;
if (popupMode) {
_this.webMessageHandler.run(authorizeOptions, cb);
_this.webMessageHandler.run(authorizeOptions, responseHandler(cb));
} else {
_this.webAuth.authorize(authorizeOptions);
}
Expand Down
52 changes: 51 additions & 1 deletion test/web-auth/cross-origin-authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,53 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
}
);
});
it('should map error correctly when popup:true', function(done) {
stub(request, 'post', function(url) {
expect(url).to.be('https://me.auth0.com/co/authenticate');
return new RequestMock({
body: {
client_id: '...',
credential_type: 'password',
username: 'me@example.com',
password: '123456'
},
headers: {
'Content-Type': 'application/json'
},
cb: function(cb) {
cb(null, {
body: {
login_ticket: 'a_login_ticket',
co_verifier: 'co_verifier',
co_id: 'co_id'
}
});
}
});
});
stub(WebMessageHandler.prototype, 'run', function(options, callback) {
callback({ error: 'any error', error_description: 'a huge error string' });
});
this.co.login(
{
username: 'me@example.com',
password: '123456',
anotherOption: 'foobar',
popup: true
},
function(err) {
expect(err).to.be.eql({
original: {
error: 'any error',
error_description: 'a huge error string'
},
code: 'any error',
description: 'a huge error string'
});
done();
}
);
});
it('should call /co/authenticate with realm grant and redirect to /authorize with login_ticket when realm is used', function() {
stub(request, 'post', function(url) {
expect(url).to.be('https://me.auth0.com/co/authenticate');
Expand Down Expand Up @@ -268,7 +315,10 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
},
function(err) {
expect(err).to.be.eql({
original: { error: 'any_error', error_description: 'a super big error message description' },
original: {
error: 'any_error',
error_description: 'a super big error message description'
},
code: 'any_error',
description: 'a super big error message description'
});
Expand Down

0 comments on commit f39ebd5

Please sign in to comment.