Bug 1070115 - pass the uid and email address of the current FxA user to the account manage url. r=zaach
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 24 Apr 2015 10:51:20 +1000
changeset 240801 d03a3e5aaf86260401786c4a6857f283ed2c4c0e
parent 240800 202a071fa1a0701c259af13df0bc03f8fdf650ee
child 240802 1fe760f5c298ebd277a9381a12687ae7c3c13d17
push id12550
push usermhammond@skippinet.com.au
push dateFri, 24 Apr 2015 00:52:43 +0000
treeherderfx-team@d03a3e5aaf86 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszaach
bugs1070115
milestone40.0a1
Bug 1070115 - pass the uid and email address of the current FxA user to the account manage url. r=zaach
browser/components/preferences/in-content/sync.js
browser/components/preferences/sync.js
services/fxaccounts/FxAccounts.jsm
--- a/browser/components/preferences/in-content/sync.js
+++ b/browser/components/preferences/in-content/sync.js
@@ -568,18 +568,22 @@ let gSyncPane = {
       .then(url => {
         this.openContentInBrowser(url, {
           replaceQueryString: true
         });
       });
   },
 
   manageFirefoxAccount: function() {
-    let url = Services.prefs.getCharPref("identity.fxaccounts.settings.uri");
-    this.openContentInBrowser(url);
+    fxAccounts.promiseAccountsManageURI()
+      .then(url => {
+        this.openContentInBrowser(url, {
+          replaceQueryString: true
+        });
+      });
   },
 
   verifyFirefoxAccount: function() {
     fxAccounts.resendVerificationEmail().then(() => {
       fxAccounts.getSignedInUser().then(data => {
         let sb = this._accountsStringBundle;
         let title = sb.GetStringFromName("verificationSentTitle");
         let heading = sb.formatStringFromName("verificationSentHeading",
--- a/browser/components/preferences/sync.js
+++ b/browser/components/preferences/sync.js
@@ -400,18 +400,22 @@ let gSyncPane = {
 
   reSignIn: function() {
     this.openContentInBrowser("about:accounts?action=reauth&entrypoint=preferences", {
       replaceQueryString: true
     });
   },
 
   manageFirefoxAccount: function() {
-    let url = Services.prefs.getCharPref("identity.fxaccounts.settings.uri");
-    this.openContentInBrowser(url);
+    fxAccounts.promiseAccountsManageURI()
+      .then(url => {
+        this.openContentInBrowser(url, {
+          replaceQueryString: true
+        });
+      });
   },
 
   verifyFirefoxAccount: function() {
     fxAccounts.resendVerificationEmail().then(() => {
       fxAccounts.getSignedInUser().then(data => {
         let sb = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
         let title = sb.GetStringFromName("verificationSentTitle");
         let heading = sb.formatStringFromName("verificationSentHeading",
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -40,16 +40,17 @@ let publicProperties = [
   "getSignedInUser",
   "getOAuthToken",
   "getSignedInUserProfile",
   "loadAndPoll",
   "localtimeOffsetMsec",
   "now",
   "promiseAccountsForceSigninURI",
   "promiseAccountsChangeProfileURI",
+  "promiseAccountsManageURI",
   "removeCachedOAuthToken",
   "resendVerificationEmail",
   "setSignedInUser",
   "signOut",
   "version",
   "whenVerified"
 ];
 
@@ -1212,16 +1213,38 @@ FxAccountsInternal.prototype = {
       }
       let newQueryPortion = url.indexOf("?") == -1 ? "?" : "&";
       newQueryPortion += "email=" + encodeURIComponent(accountData.email);
       newQueryPortion += "&uid=" + encodeURIComponent(accountData.uid);
       return url + newQueryPortion;
     }).then(result => currentState.resolve(result));
   },
 
+  // Returns a promise that resolves with the URL to use to manage the current
+  // user's FxA acct.
+  promiseAccountsManageURI: function() {
+    let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.settings.uri");
+    if (this._requireHttps() && !/^https:/.test(url)) { // Comment to un-break emacs js-mode highlighting
+      throw new Error("Firefox Accounts server must use HTTPS");
+    }
+    let currentState = this.currentAccountState;
+    // but we need to append the uid and email address onto a query string
+    // (if the server has no matching uid it will offer to sign in with the
+    // email address)
+    return this.getSignedInUser().then(accountData => {
+      if (!accountData) {
+        return null;
+      }
+      let newQueryPortion = url.indexOf("?") == -1 ? "?" : "&";
+      newQueryPortion += "uid=" + encodeURIComponent(accountData.uid) +
+                         "&email=" + encodeURIComponent(accountData.email);
+      return url + newQueryPortion;
+    }).then(result => currentState.resolve(result));
+  },
+
   /**
    * Get an OAuth token for the user
    *
    * @param options
    *        {
    *          scope: (string/array) the oauth scope(s) being requested. As a
    *                 convenience, you may pass a string if only one scope is
    *                 required, or an array of strings if multiple are needed.