Index: chrome/browser/resources/gaia_auth/main.js |
diff --git a/chrome/browser/resources/gaia_auth/main.js b/chrome/browser/resources/gaia_auth/main.js |
index b9a57d86509da88b9b06adcc02faa24e00d563f6..ba48c65dc9049f2dc8cb453d754480286497b3f8 100644 |
--- a/chrome/browser/resources/gaia_auth/main.js |
+++ b/chrome/browser/resources/gaia_auth/main.js |
@@ -48,7 +48,6 @@ |
Authenticator.prototype = { |
email_: null, |
- gaiaId_: null, |
// Depending on the key type chosen, this will contain the plain text password |
// or a credential derived from it along with the information required to |
@@ -57,9 +56,6 @@ |
// when support for key types other than plain text password is added. |
passwordBytes_: null, |
- chooseWhatToSync_: false, |
- skipForNow_: false, |
- sessionIndex_: null, |
attemptToken_: null, |
// Input params from extension initialization URL. |
@@ -108,6 +104,10 @@ |
this.GAIA_URL.indexOf(msg.origin) == 0; |
}, |
+ isInternalMessage_: function(msg) { |
+ return msg.origin == Authenticator.THIS_EXTENSION_ORIGIN; |
+ }, |
+ |
isParentMessage_: function(msg) { |
return msg.origin == this.parentPage_; |
}, |
@@ -165,9 +165,9 @@ |
}); |
this.supportChannel_.registerMessage( |
'switchToFullTab', this.switchToFullTab_.bind(this)); |
- } |
- this.supportChannel_.registerMessage( |
- 'completeLogin', this.onCompleteLogin_.bind(this)); |
+ this.supportChannel_.registerMessage( |
+ 'completeLogin', this.completeLogin_.bind(this)); |
+ } |
this.initSAML_(); |
this.maybeInitialized_(); |
}.bind(this)); |
@@ -198,7 +198,7 @@ |
/** |
* Invoked when the background script sends a message to indicate that the |
* current content does not fit in a constrained window. |
- * @param {Object=} msg Extra info to send. |
+ * @param {Object=} opt_extraMsg Optional extra info to send. |
*/ |
switchToFullTab_: function(msg) { |
var parentMsg = { |
@@ -220,11 +220,8 @@ |
this.passwordBytes_, |
'usingSAML': this.isSAMLFlow_, |
'chooseWhatToSync': this.chooseWhatToSync_ || false, |
- 'skipForNow': (opt_extraMsg && opt_extraMsg.skipForNow) || |
- this.skipForNow_, |
- 'sessionIndex': (opt_extraMsg && opt_extraMsg.sessionIndex) || |
- this.sessionIndex_, |
- 'gaiaId': (opt_extraMsg && opt_extraMsg.gaiaId) || this.gaiaId_ |
+ 'skipForNow': opt_extraMsg && opt_extraMsg.skipForNow, |
+ 'sessionIndex': opt_extraMsg && opt_extraMsg.sessionIndex |
}; |
window.parent.postMessage(msg, this.parentPage_); |
this.supportChannel_.send({name: 'resetAuth'}); |
@@ -271,7 +268,6 @@ |
// from the GAIA login form are no longer relevant and can be discarded. |
this.isSAMLFlow_ = true; |
this.email_ = null; |
- this.gaiaId_ = null; |
this.passwordBytes_ = null; |
} |
@@ -320,9 +316,8 @@ |
console.error('Authenticator.onAPICall_: unsupported key type'); |
return; |
} |
- // Not setting |email_| and |gaiaId_| because this API call will |
- // eventually be followed by onCompleteLogin_() which does set it. |
this.apiToken_ = call.token; |
+ this.email_ = call.user; |
this.passwordBytes_ = call.passwordBytes; |
} else if (call.method == 'confirm') { |
if (call.token != this.apiToken_) |
@@ -347,34 +342,21 @@ |
}); |
}, |
- /** |
- * Callback invoked for 'completeLogin' message. |
- * @param {Object=} msg Message sent from background page. |
- */ |
- onCompleteLogin_: function(msg) { |
- if (!msg.email || !msg.gaiaId || !msg.sessionIndex) { |
- console.error('Missing fields to complete login.'); |
- window.parent.postMessage({method: 'missingGaiaInfo'}, this.parentPage_); |
+ onConfirmLogin_: function() { |
+ if (!this.isSAMLFlow_) { |
+ this.completeLogin_(); |
return; |
} |
- // Skip SAML extra steps for desktop flow and non-SAML flow. |
- if (!this.isSAMLFlow_ || this.desktopMode_) { |
- this.completeLogin_(msg); |
- return; |
- } |
- |
- this.email_ = msg.email; |
- this.gaiaId_ = msg.gaiaId; |
- // Password from |msg| is not used because ChromeOS SAML flow |
- // gets password by asking user to confirm. |
- this.skipForNow_ = msg.skipForNow; |
- this.sessionIndex_ = msg.sessionIndex; |
- |
- if (this.passwordBytes_) { |
- window.parent.postMessage({method: 'samlApiUsed'}, this.parentPage_); |
- this.completeLogin_(msg); |
- } else { |
+ var apiUsed = !!this.passwordBytes_; |
+ |
+ // Retrieve the e-mail address of the user who just authenticated from GAIA. |
+ window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', |
+ attemptToken: this.attemptToken_, |
+ apiUsed: apiUsed}, |
+ this.parentPage_); |
+ |
+ if (!apiUsed) { |
this.supportChannel_.sendWithCallback( |
{name: 'getScrapedPasswords'}, |
function(passwords) { |
@@ -392,6 +374,13 @@ |
} |
}, |
+ maybeCompleteSAMLLogin_: function() { |
+ // SAML login is complete when the user's e-mail address has been retrieved |
+ // from GAIA and the user has successfully confirmed the password. |
+ if (this.email_ !== null && this.passwordBytes_ !== null) |
+ this.completeLogin_(); |
+ }, |
+ |
onVerifyConfirmedPassword_: function(password) { |
this.supportChannel_.sendWithCallback( |
{name: 'getScrapedPasswords'}, |
@@ -399,10 +388,7 @@ |
for (var i = 0; i < passwords.length; ++i) { |
if (passwords[i] == password) { |
this.passwordBytes_ = passwords[i]; |
- // SAML login is complete when the user has successfully |
- // confirmed the password. |
- if (this.passwordBytes_ !== null) |
- this.completeLogin_(); |
+ this.maybeCompleteSAMLLogin_(); |
return; |
} |
} |
@@ -415,7 +401,6 @@ |
onMessage: function(e) { |
var msg = e.data; |
if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { |
- // At this point GAIA does not yet know the gaiaId, so its not set here. |
this.email_ = msg.email; |
this.passwordBytes_ = msg.password; |
this.attemptToken_ = msg.attemptToken; |
@@ -431,15 +416,27 @@ |
this.maybeInitialized_(); |
} |
this.email_ = null; |
- this.gaiaId_ = null; |
- this.sessionIndex_ = false; |
this.passwordBytes_ = null; |
this.attemptToken_ = null; |
this.isSAMLFlow_ = false; |
- this.skipForNow_ = false; |
- this.chooseWhatToSync_ = false; |
if (this.supportChannel_) |
this.supportChannel_.send({name: 'resetAuth'}); |
+ } else if (msg.method == 'setAuthenticatedUserEmail' && |
+ this.isParentMessage_(e)) { |
+ if (this.attemptToken_ == msg.attemptToken) { |
+ this.email_ = msg.email; |
+ this.maybeCompleteSAMLLogin_(); |
+ } |
+ } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { |
+ // In the desktop mode, Chrome needs to wait for extra info such as |
+ // session index from the background JS. |
+ if (this.desktopMode_) |
+ return; |
+ |
+ if (this.attemptToken_ == msg.attemptToken) |
+ this.onConfirmLogin_(); |
+ else |
+ console.error('Authenticator.onMessage: unexpected attemptToken!?'); |
} else if (msg.method == 'verifyConfirmedPassword' && |
this.isParentMessage_(e)) { |
this.onVerifyConfirmedPassword_(msg.password); |