diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 3f9654bf5b8..360134ee53e 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -1087,6 +1087,9 @@ pref("identity.fxaccounts.enabled", true); // Mobile Identity API. pref("services.mobileid.server.uri", "https://msisdn.services.mozilla.com"); +pref("identity.fxaccounts.remote.oauth.uri", "https://oauth.accounts.firefox.com/v1"); +pref("identity.fxaccounts.remote.profile.uri", "https://profile.accounts.firefox.com/v1"); + // Enable mapped array buffer. #ifndef XP_WIN pref("dom.mapped_arraybuffer.enabled", true); diff --git a/services/fxaccounts/FxAccountsManager.jsm b/services/fxaccounts/FxAccountsManager.jsm index 3dbf23ebeb3..4e0ac7f6d2a 100644 --- a/services/fxaccounts/FxAccountsManager.jsm +++ b/services/fxaccounts/FxAccountsManager.jsm @@ -62,7 +62,8 @@ this.FxAccountsManager = { return { email: this._activeSession.email, - verified: this._activeSession.verified + verified: this._activeSession.verified, + profile: this._activeSession.profile, } }, @@ -165,12 +166,22 @@ this.FxAccountsManager = { this._fxAccounts.getKeys(); } - return Promise.resolve({ - accountCreated: aMethod === "signUp", - user: this._user + return this._fxAccounts.getSignedInUserProfile().catch(error => { + // Not fetching the profile is sad but the FxA logs will already + // have noise. + return null; }); } - ); + ).then(profile => { + if (profile) { + this._activeSession.profile = profile; + } + + return Promise.resolve({ + accountCreated: aMethod === "signUp", + user: this._user + }); + }); }, reason => { return this._serverError(reason); } ); @@ -420,10 +431,23 @@ this.FxAccountsManager = { // we kick off verification before returning what we have. if (!user.verified) { this.verificationStatus(user); + // Trying to get the profile for unverified users will fail, so we + // don't even try in that case. + log.debug("Account ", this._user); + return Promise.resolve(this._user); } - log.debug("Account " + JSON.stringify(this._user)); - return Promise.resolve(this._user); + return this._fxAccounts.getSignedInUserProfile().then(profile => { + if (profile) { + this._activeSession.profile = profile; + } + log.debug("Account ", this._user); + return Promise.resolve(this._user); + }).catch(error => { + // FxAccounts logs already inform about the error. + log.debug("Account ", this._user); + return Promise.resolve(this._user); + }); } ); }, @@ -486,6 +510,13 @@ this.FxAccountsManager = { if (this._activeSession.verified != data.verified) { this._activeSession.verified = data.verified; this._fxAccounts.setSignedInUser(this._activeSession); + this._fxAccounts.getSignedInUserProfile().then(profile => { + if (profile) { + this._activeSession.profile = profile; + } + }).catch(error => { + // FxAccounts logs already inform about the error. + }); } log.debug(JSON.stringify(this._user)); }, diff --git a/services/fxaccounts/tests/xpcshell/test_manager.js b/services/fxaccounts/tests/xpcshell/test_manager.js index c3335bca68d..395fcb6a32b 100644 --- a/services/fxaccounts/tests/xpcshell/test_manager.js +++ b/services/fxaccounts/tests/xpcshell/test_manager.js @@ -102,6 +102,7 @@ FxAccountsManager._fxAccounts = { _error: 'error', _assertion: 'assertion', _keys: 'keys', + _profile: 'aprofile', _signedInUser: null, _reset: function() { @@ -140,6 +141,13 @@ FxAccountsManager._fxAccounts = { return deferred.promise; }, + getSignedInUserProfile: function() { + let deferred = Promise.defer(); + this._reject ? deferred.reject(this._error) + : deferred.resolve(this._profile); + return deferred.promise; + }, + getKeys: function() { let deferred = Promise.defer(); this._reject ? deferred.reject(this._error) @@ -636,11 +644,13 @@ add_test(function(test_getAssertion_refresh_auth_no_refresh) { add_test(function(test_getAccount_existing_verified_session) { do_print("= getAccount, existing verified session ="); + FxAccountsManager._activeSession = null; FxAccountsManager.getAccount().then( result => { - do_check_false(FxAccountsManager._fxAccounts._getSignedInUserCalled); + do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled); do_check_eq(result.email, FxAccountsManager._user.email); do_check_eq(result.verified, FxAccountsManager._user.verified); + do_check_eq(result.profile, "aprofile"); run_next_test(); }, error => {