diff --git a/src/helper/response-handler.js b/src/helper/response-handler.js index caf86f72..4547280d 100644 --- a/src/helper/response-handler.js +++ b/src/helper/response-handler.js @@ -42,7 +42,6 @@ function wrapCallback(cb, options) { if (err.err) { err = err.err; } - errObj.code = err.error || err.code || err.error_code || err.status || null; errObj.description = err.errorDescription || @@ -52,6 +51,10 @@ function wrapCallback(cb, options) { err.details || err.err || null; + if (options.forceLegacyError) { + errObj.error = errObj.code; + errObj.error_description = errObj.description; + } if (err.name) { errObj.name = err.name; diff --git a/src/web-auth/cross-origin-authentication.js b/src/web-auth/cross-origin-authentication.js index 70646979..974684c6 100644 --- a/src/web-auth/cross-origin-authentication.js +++ b/src/web-auth/cross-origin-authentication.js @@ -71,7 +71,7 @@ CrossOriginAuthentication.prototype.login = function(options, cb) { error: 'request_error', error_description: JSON.stringify(err) }; - return responseHandler(cb)(errorObject); + return responseHandler(cb, { forceLegacyError: true })(errorObject); } var popupMode = options.popup === true; options = objectHelper.blacklist(options, ['password', 'credentialType', 'otp', 'popup']); @@ -81,7 +81,10 @@ 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, responseHandler(cb)); + _this.webMessageHandler.run( + authorizeOptions, + responseHandler(cb, { forceLegacyError: true }) + ); } else { _this.webAuth.authorize(authorizeOptions); } diff --git a/test/web-auth/cross-origin-authentication.test.js b/test/web-auth/cross-origin-authentication.test.js index 1b309bdf..17d7ed2b 100644 --- a/test/web-auth/cross-origin-authentication.test.js +++ b/test/web-auth/cross-origin-authentication.test.js @@ -166,7 +166,9 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() { error_description: 'a huge error string' }, code: 'any error', - description: 'a huge error string' + description: 'a huge error string', + error: 'any error', + error_description: 'a huge error string' }); done(); } @@ -320,7 +322,9 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() { error_description: 'a super big error message description' }, code: 'any_error', - description: 'a super big error message description' + description: 'a super big error message description', + error: 'any_error', + error_description: 'a super big error message description' }); expect(_this.webAuthSpy.authorize.called).to.be.eql(false); done(); @@ -359,7 +363,9 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() { error_description: '{"some":"error"}' }, code: 'request_error', - description: '{"some":"error"}' + description: '{"some":"error"}', + error: 'request_error', + error_description: '{"some":"error"}' }); expect(_this.webAuthSpy.authorize.called).to.be.eql(false); done();