Repository: auth0/auth0.js
Pull request #685 (2018-03-02 18:27:44)

Adding legacy error handling for co/auth endpoint


Patch:
diff --git a/src/helper/response-handler.js b/src/helper/response-handler.js
index caf86f7..4547280 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 7064697..974684c 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);
     }


Test patch:
diff --git a/test/web-auth/cross-origin-authentication.test.js b/test/web-auth/cross-origin-authentication.test.js
index 1b309bd..17d7ed2 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();