Skip to content

Commit f39ebd5

Browse files
authored
Fixing error handling for auth in poopup mode (#668)
1 parent 63c7486 commit f39ebd5

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/web-auth/cross-origin-authentication.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ CrossOriginAuthentication.prototype.login = function(options, cb) {
8181
var key = createKey(_this.baseOptions.rootUrl, data.body.co_id);
8282
theWindow.sessionStorage[key] = data.body.co_verifier;
8383
if (popupMode) {
84-
_this.webMessageHandler.run(authorizeOptions, cb);
84+
_this.webMessageHandler.run(authorizeOptions, responseHandler(cb));
8585
} else {
8686
_this.webAuth.authorize(authorizeOptions);
8787
}

test/web-auth/cross-origin-authentication.test.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,53 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
125125
}
126126
);
127127
});
128+
it('should map error correctly when popup:true', function(done) {
129+
stub(request, 'post', function(url) {
130+
expect(url).to.be('https://me.auth0.com/co/authenticate');
131+
return new RequestMock({
132+
body: {
133+
client_id: '...',
134+
credential_type: 'password',
135+
username: '[email protected]',
136+
password: '123456'
137+
},
138+
headers: {
139+
'Content-Type': 'application/json'
140+
},
141+
cb: function(cb) {
142+
cb(null, {
143+
body: {
144+
login_ticket: 'a_login_ticket',
145+
co_verifier: 'co_verifier',
146+
co_id: 'co_id'
147+
}
148+
});
149+
}
150+
});
151+
});
152+
stub(WebMessageHandler.prototype, 'run', function(options, callback) {
153+
callback({ error: 'any error', error_description: 'a huge error string' });
154+
});
155+
this.co.login(
156+
{
157+
username: '[email protected]',
158+
password: '123456',
159+
anotherOption: 'foobar',
160+
popup: true
161+
},
162+
function(err) {
163+
expect(err).to.be.eql({
164+
original: {
165+
error: 'any error',
166+
error_description: 'a huge error string'
167+
},
168+
code: 'any error',
169+
description: 'a huge error string'
170+
});
171+
done();
172+
}
173+
);
174+
});
128175
it('should call /co/authenticate with realm grant and redirect to /authorize with login_ticket when realm is used', function() {
129176
stub(request, 'post', function(url) {
130177
expect(url).to.be('https://me.auth0.com/co/authenticate');
@@ -268,7 +315,10 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
268315
},
269316
function(err) {
270317
expect(err).to.be.eql({
271-
original: { error: 'any_error', error_description: 'a super big error message description' },
318+
original: {
319+
error: 'any_error',
320+
error_description: 'a super big error message description'
321+
},
272322
code: 'any_error',
273323
description: 'a super big error message description'
274324
});

0 commit comments

Comments
 (0)