Bug 1612717 - the case where the OAuth2 token expired should be handled with success to retrigger the authentication flow. r=Fallen
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 25 Feb 2020 10:44:33 +0200
changeset 37428 f31e6d1534440f26b7ebebab08e1db86227e2d8a
parent 37427 f34fd430a920b192011a843926cc975366c9df9d
child 37429 581b8fbdb8e2d7eb2ed228b8a0358a29ab5564f4
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFallen
bugs1612717
Bug 1612717 - the case where the OAuth2 token expired should be handled with success to retrigger the authentication flow. r=Fallen
mailnews/base/util/OAuth2.jsm
--- a/mailnews/base/util/OAuth2.jsm
+++ b/mailnews/base/util/OAuth2.jsm
@@ -246,17 +246,23 @@ OAuth2.prototype = {
       .then(result => {
         if ("error" in result) {
           // RFC 6749 section 5.2. Error Response
           this.log.info(
             `The authorization server returned an error response: ${JSON.stringify(
               result
             )}`
           );
-          this.connectFailureCallback(result);
+          // Typically in production this would be {"error": "invalid_grant"}.
+          // That is, the token expired or was revoked (user changed password?).
+          // Reset the tokens we have and call success so that the auth flow
+          // will be re-triggered.
+          this.accessToken = null;
+          this.refreshToken = null;
+          this.connectSuccessCallback();
           return;
         }
 
         // RFC 6749 section 5.1. Successful Response
         this.log.info("The authorization server issued an access token.");
         this.accessToken = result.access_token;
         if ("refresh_token" in result) {
           this.refreshToken = result.refresh_token;