From 8a61e04761cd522e3ffb325f47ddbc5a980945a8 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Fri, 24 Apr 2015 10:51:20 +1000 Subject: [PATCH] Bug 1070115 - pass the uid and email address of the current FxA user to the account manage url. r=zaach --- .../components/preferences/in-content/sync.js | 8 +++++-- browser/components/preferences/sync.js | 8 +++++-- services/fxaccounts/FxAccounts.jsm | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/browser/components/preferences/in-content/sync.js b/browser/components/preferences/in-content/sync.js index 6dc64e72b86..6ff4e8cb623 100644 --- a/browser/components/preferences/in-content/sync.js +++ b/browser/components/preferences/in-content/sync.js @@ -573,8 +573,12 @@ let gSyncPane = { }, 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() { diff --git a/browser/components/preferences/sync.js b/browser/components/preferences/sync.js index 88970da6dc8..2cb8ee49694 100644 --- a/browser/components/preferences/sync.js +++ b/browser/components/preferences/sync.js @@ -405,8 +405,12 @@ let gSyncPane = { }, 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() { diff --git a/services/fxaccounts/FxAccounts.jsm b/services/fxaccounts/FxAccounts.jsm index 093fd9db80c..3836b7e76b1 100644 --- a/services/fxaccounts/FxAccounts.jsm +++ b/services/fxaccounts/FxAccounts.jsm @@ -45,6 +45,7 @@ let publicProperties = [ "now", "promiseAccountsForceSigninURI", "promiseAccountsChangeProfileURI", + "promiseAccountsManageURI", "removeCachedOAuthToken", "resendVerificationEmail", "setSignedInUser", @@ -1217,6 +1218,28 @@ FxAccountsInternal.prototype = { }).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 *