Bug 1229023 - Fetch and expose Firefox Accounts profile data. r=markh

This commit is contained in:
Fernando Jimenez 2015-12-02 19:41:27 +01:00
parent b5c45c717e
commit 0a449a3f97
3 changed files with 52 additions and 8 deletions

View File

@ -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);

View File

@ -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));
},

View File

@ -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 => {