Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
| 7 */ | 7 */ |
| 8 function Authenticator() { | 8 function Authenticator() { |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 */ | 41 */ |
| 42 Authenticator.getInstance = function() { | 42 Authenticator.getInstance = function() { |
| 43 if (!Authenticator.instance_) { | 43 if (!Authenticator.instance_) { |
| 44 Authenticator.instance_ = new Authenticator(); | 44 Authenticator.instance_ = new Authenticator(); |
| 45 } | 45 } |
| 46 return Authenticator.instance_; | 46 return Authenticator.instance_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 Authenticator.prototype = { | 49 Authenticator.prototype = { |
| 50 email_: null, | 50 email_: null, |
| 51 gaiaId_: null, | |
| 51 | 52 |
| 52 // Depending on the key type chosen, this will contain the plain text password | 53 // Depending on the key type chosen, this will contain the plain text password |
| 53 // or a credential derived from it along with the information required to | 54 // or a credential derived from it along with the information required to |
| 54 // repeat the derivation, such as a salt. The information will be encoded so | 55 // repeat the derivation, such as a salt. The information will be encoded so |
| 55 // that it contains printable ASCII characters only. The exact encoding is TBD | 56 // that it contains printable ASCII characters only. The exact encoding is TBD |
| 56 // when support for key types other than plain text password is added. | 57 // when support for key types other than plain text password is added. |
| 57 passwordBytes_: null, | 58 passwordBytes_: null, |
| 58 | 59 |
| 59 attemptToken_: null, | 60 attemptToken_: null, |
| 60 | 61 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 159 |
| 159 if (this.desktopMode_) { | 160 if (this.desktopMode_) { |
| 160 this.supportChannel_.send({ | 161 this.supportChannel_.send({ |
| 161 name: 'initDesktopFlow', | 162 name: 'initDesktopFlow', |
| 162 gaiaUrl: this.gaiaUrl_, | 163 gaiaUrl: this.gaiaUrl_, |
| 163 continueUrl: stripParams(this.continueUrl_), | 164 continueUrl: stripParams(this.continueUrl_), |
| 164 isConstrainedWindow: this.isConstrainedWindow_ | 165 isConstrainedWindow: this.isConstrainedWindow_ |
| 165 }); | 166 }); |
| 166 this.supportChannel_.registerMessage( | 167 this.supportChannel_.registerMessage( |
| 167 'switchToFullTab', this.switchToFullTab_.bind(this)); | 168 'switchToFullTab', this.switchToFullTab_.bind(this)); |
| 168 this.supportChannel_.registerMessage( | |
| 169 'completeLogin', this.completeLogin_.bind(this)); | |
| 170 } | 169 } |
| 170 this.supportChannel_.registerMessage( | |
| 171 'completeLogin', this.completeLogin_.bind(this)); | |
|
xiyuan
2014/09/25 02:52:39
Think we need to merge onConfirmLogin_ with comple
Roger Tawa OOO till Jul 10th
2014/09/25 20:36:41
Now calls maybeCompleteLogin_(), which is the rena
| |
| 171 this.initSAML_(); | 172 this.initSAML_(); |
| 172 this.maybeInitialized_(); | 173 this.maybeInitialized_(); |
| 173 }.bind(this)); | 174 }.bind(this)); |
| 174 | 175 |
| 175 window.setTimeout(function() { | 176 window.setTimeout(function() { |
| 176 if (!this.supportChannel_) { | 177 if (!this.supportChannel_) { |
| 177 // Re-initialize the channel if it is not connected properly, e.g. | 178 // Re-initialize the channel if it is not connected properly, e.g. |
| 178 // connect may be called before background script started running. | 179 // connect may be called before background script started running. |
| 179 this.initSupportChannel_(); | 180 this.initSupportChannel_(); |
| 180 } | 181 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 */ | 215 */ |
| 215 completeLogin_: function(opt_extraMsg) { | 216 completeLogin_: function(opt_extraMsg) { |
| 216 var msg = { | 217 var msg = { |
| 217 'method': 'completeLogin', | 218 'method': 'completeLogin', |
| 218 'email': (opt_extraMsg && opt_extraMsg.email) || this.email_, | 219 'email': (opt_extraMsg && opt_extraMsg.email) || this.email_, |
| 219 'password': (opt_extraMsg && opt_extraMsg.password) || | 220 'password': (opt_extraMsg && opt_extraMsg.password) || |
| 220 this.passwordBytes_, | 221 this.passwordBytes_, |
| 221 'usingSAML': this.isSAMLFlow_, | 222 'usingSAML': this.isSAMLFlow_, |
| 222 'chooseWhatToSync': this.chooseWhatToSync_ || false, | 223 'chooseWhatToSync': this.chooseWhatToSync_ || false, |
| 223 'skipForNow': opt_extraMsg && opt_extraMsg.skipForNow, | 224 'skipForNow': opt_extraMsg && opt_extraMsg.skipForNow, |
| 224 'sessionIndex': opt_extraMsg && opt_extraMsg.sessionIndex | 225 'sessionIndex': opt_extraMsg && opt_extraMsg.sessionIndex, |
| 225 }; | 226 'gaiaId': (opt_extraMsg && opt_extraMsg.gaiaId) || this.gaiaId_ |
| 227 }; | |
| 226 window.parent.postMessage(msg, this.parentPage_); | 228 window.parent.postMessage(msg, this.parentPage_); |
| 227 this.supportChannel_.send({name: 'resetAuth'}); | 229 this.supportChannel_.send({name: 'resetAuth'}); |
| 228 }, | 230 }, |
| 229 | 231 |
| 230 /** | 232 /** |
| 231 * Invoked when support channel is connected. | 233 * Invoked when support channel is connected. |
| 232 */ | 234 */ |
| 233 initSAML_: function() { | 235 initSAML_: function() { |
| 234 this.isSAMLFlow_ = false; | 236 this.isSAMLFlow_ = false; |
| 235 | 237 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 261 */ | 263 */ |
| 262 onAuthPageLoaded_: function(msg) { | 264 onAuthPageLoaded_: function(msg) { |
| 263 var isSAMLPage = msg.url.indexOf(this.gaiaUrl_) != 0; | 265 var isSAMLPage = msg.url.indexOf(this.gaiaUrl_) != 0; |
| 264 | 266 |
| 265 if (isSAMLPage && !this.isSAMLFlow_) { | 267 if (isSAMLPage && !this.isSAMLFlow_) { |
| 266 // GAIA redirected to a SAML login page. The credentials provided to this | 268 // GAIA redirected to a SAML login page. The credentials provided to this |
| 267 // page will determine what user gets logged in. The credentials obtained | 269 // page will determine what user gets logged in. The credentials obtained |
| 268 // from the GAIA login form are no longer relevant and can be discarded. | 270 // from the GAIA login form are no longer relevant and can be discarded. |
| 269 this.isSAMLFlow_ = true; | 271 this.isSAMLFlow_ = true; |
| 270 this.email_ = null; | 272 this.email_ = null; |
| 273 this.gaiaId_ = null; | |
| 271 this.passwordBytes_ = null; | 274 this.passwordBytes_ = null; |
| 272 } | 275 } |
| 273 | 276 |
| 274 window.parent.postMessage({ | 277 window.parent.postMessage({ |
| 275 'method': 'authPageLoaded', | 278 'method': 'authPageLoaded', |
| 276 'isSAML': this.isSAMLFlow_, | 279 'isSAML': this.isSAMLFlow_, |
| 277 'domain': extractDomain(msg.url) | 280 'domain': extractDomain(msg.url) |
| 278 }, this.parentPage_); | 281 }, this.parentPage_); |
| 279 }, | 282 }, |
| 280 | 283 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 311 return; | 314 return; |
| 312 } | 315 } |
| 313 | 316 |
| 314 if (call.method == 'add') { | 317 if (call.method == 'add') { |
| 315 if (Authenticator.API_KEY_TYPES.indexOf(call.keyType) == -1) { | 318 if (Authenticator.API_KEY_TYPES.indexOf(call.keyType) == -1) { |
| 316 console.error('Authenticator.onAPICall_: unsupported key type'); | 319 console.error('Authenticator.onAPICall_: unsupported key type'); |
| 317 return; | 320 return; |
| 318 } | 321 } |
| 319 this.apiToken_ = call.token; | 322 this.apiToken_ = call.token; |
| 320 this.email_ = call.user; | 323 this.email_ = call.user; |
| 324 this.gaiaId_ = null; // TODO(rogerta): no idea what to do here. | |
| 321 this.passwordBytes_ = call.passwordBytes; | 325 this.passwordBytes_ = call.passwordBytes; |
| 322 } else if (call.method == 'confirm') { | 326 } else if (call.method == 'confirm') { |
| 323 if (call.token != this.apiToken_) | 327 if (call.token != this.apiToken_) |
| 324 console.error('Authenticator.onAPICall_: token mismatch'); | 328 console.error('Authenticator.onAPICall_: token mismatch'); |
| 325 } else { | 329 } else { |
| 326 console.error('Authenticator.onAPICall_: unknown message'); | 330 console.error('Authenticator.onAPICall_: unknown message'); |
| 327 } | 331 } |
| 328 }, | 332 }, |
| 329 | 333 |
| 330 sendInitializationSuccess_: function() { | 334 sendInitializationSuccess_: function() { |
| 331 this.supportChannel_.send({name: 'apiResponse', response: { | 335 this.supportChannel_.send({name: 'apiResponse', response: { |
| 332 result: 'initialized', | 336 result: 'initialized', |
| 333 version: this.apiVersion_, | 337 version: this.apiVersion_, |
| 334 keyTypes: Authenticator.API_KEY_TYPES | 338 keyTypes: Authenticator.API_KEY_TYPES |
| 335 }}); | 339 }}); |
| 336 }, | 340 }, |
| 337 | 341 |
| 338 sendInitializationFailure_: function() { | 342 sendInitializationFailure_: function() { |
| 339 this.supportChannel_.send({ | 343 this.supportChannel_.send({ |
| 340 name: 'apiResponse', | 344 name: 'apiResponse', |
| 341 response: {result: 'initialization_failed'} | 345 response: {result: 'initialization_failed'} |
| 342 }); | 346 }); |
| 343 }, | 347 }, |
| 344 | 348 |
| 345 onConfirmLogin_: function() { | 349 onConfirmLogin_: function() { |
| 346 if (!this.isSAMLFlow_) { | 350 if (!this.isSAMLFlow_) |
| 347 this.completeLogin_(); | |
| 348 return; | 351 return; |
| 349 } | |
| 350 | 352 |
| 351 var apiUsed = !!this.passwordBytes_; | 353 var apiUsed = !!this.passwordBytes_; |
| 352 | 354 |
| 353 // Retrieve the e-mail address of the user who just authenticated from GAIA. | 355 // Retrieve the e-mail address of the user who just authenticated from GAIA. |
| 354 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', | 356 window.parent.postMessage({method: 'retrieveAuthenticatedUserEmail', |
| 355 attemptToken: this.attemptToken_, | 357 attemptToken: this.attemptToken_, |
| 356 apiUsed: apiUsed}, | 358 apiUsed: apiUsed}, |
| 357 this.parentPage_); | 359 this.parentPage_); |
| 358 | 360 |
| 359 if (!apiUsed) { | 361 if (!apiUsed) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 370 passwordCount: passwords.length}, | 372 passwordCount: passwords.length}, |
| 371 this.parentPage_); | 373 this.parentPage_); |
| 372 } | 374 } |
| 373 }.bind(this)); | 375 }.bind(this)); |
| 374 } | 376 } |
| 375 }, | 377 }, |
| 376 | 378 |
| 377 maybeCompleteSAMLLogin_: function() { | 379 maybeCompleteSAMLLogin_: function() { |
| 378 // SAML login is complete when the user's e-mail address has been retrieved | 380 // SAML login is complete when the user's e-mail address has been retrieved |
| 379 // from GAIA and the user has successfully confirmed the password. | 381 // from GAIA and the user has successfully confirmed the password. |
| 380 if (this.email_ !== null && this.passwordBytes_ !== null) | 382 if (this.email_ !== null && this.gaiaId_ !== null && |
| 383 this.passwordBytes_ !== null) { | |
| 381 this.completeLogin_(); | 384 this.completeLogin_(); |
| 385 } | |
| 382 }, | 386 }, |
| 383 | 387 |
| 384 onVerifyConfirmedPassword_: function(password) { | 388 onVerifyConfirmedPassword_: function(password) { |
| 385 this.supportChannel_.sendWithCallback( | 389 this.supportChannel_.sendWithCallback( |
| 386 {name: 'getScrapedPasswords'}, | 390 {name: 'getScrapedPasswords'}, |
| 387 function(passwords) { | 391 function(passwords) { |
| 388 for (var i = 0; i < passwords.length; ++i) { | 392 for (var i = 0; i < passwords.length; ++i) { |
| 389 if (passwords[i] == password) { | 393 if (passwords[i] == password) { |
| 390 this.passwordBytes_ = passwords[i]; | 394 this.passwordBytes_ = passwords[i]; |
| 391 this.maybeCompleteSAMLLogin_(); | 395 this.maybeCompleteSAMLLogin_(); |
| 392 return; | 396 return; |
| 393 } | 397 } |
| 394 } | 398 } |
| 395 window.parent.postMessage( | 399 window.parent.postMessage( |
| 396 {method: 'confirmPassword', email: this.email_}, | 400 {method: 'confirmPassword', email: this.email_}, |
| 397 this.parentPage_); | 401 this.parentPage_); |
| 398 }.bind(this)); | 402 }.bind(this)); |
| 399 }, | 403 }, |
| 400 | 404 |
| 401 onMessage: function(e) { | 405 onMessage: function(e) { |
| 402 var msg = e.data; | 406 var msg = e.data; |
| 403 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { | 407 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { |
| 408 // At this point GAIA does not yet know the gaiaId, so its not set here. | |
| 404 this.email_ = msg.email; | 409 this.email_ = msg.email; |
| 405 this.passwordBytes_ = msg.password; | 410 this.passwordBytes_ = msg.password; |
| 406 this.attemptToken_ = msg.attemptToken; | 411 this.attemptToken_ = msg.attemptToken; |
| 407 this.chooseWhatToSync_ = msg.chooseWhatToSync; | 412 this.chooseWhatToSync_ = msg.chooseWhatToSync; |
| 408 this.isSAMLFlow_ = false; | 413 this.isSAMLFlow_ = false; |
| 409 if (this.supportChannel_) | 414 if (this.supportChannel_) |
| 410 this.supportChannel_.send({name: 'startAuth'}); | 415 this.supportChannel_.send({name: 'startAuth'}); |
| 411 else | 416 else |
| 412 console.error('Support channel is not initialized.'); | 417 console.error('Support channel is not initialized.'); |
| 413 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { | 418 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { |
| 414 if (!this.gaiaLoaded_) { | 419 if (!this.gaiaLoaded_) { |
| 415 this.gaiaLoaded_ = true; | 420 this.gaiaLoaded_ = true; |
| 416 this.maybeInitialized_(); | 421 this.maybeInitialized_(); |
| 417 } | 422 } |
| 418 this.email_ = null; | 423 this.email_ = null; |
| 424 this.gaiaId_ = null; | |
| 419 this.passwordBytes_ = null; | 425 this.passwordBytes_ = null; |
| 420 this.attemptToken_ = null; | 426 this.attemptToken_ = null; |
| 421 this.isSAMLFlow_ = false; | 427 this.isSAMLFlow_ = false; |
| 422 if (this.supportChannel_) | 428 if (this.supportChannel_) |
| 423 this.supportChannel_.send({name: 'resetAuth'}); | 429 this.supportChannel_.send({name: 'resetAuth'}); |
| 424 } else if (msg.method == 'setAuthenticatedUserEmail' && | 430 } else if (msg.method == 'setAuthenticatedUserEmail' && |
| 425 this.isParentMessage_(e)) { | 431 this.isParentMessage_(e)) { |
| 426 if (this.attemptToken_ == msg.attemptToken) { | 432 if (this.attemptToken_ == msg.attemptToken) { |
| 427 this.email_ = msg.email; | 433 this.email_ = msg.email; |
| 428 this.maybeCompleteSAMLLogin_(); | 434 this.maybeCompleteSAMLLogin_(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 443 } else if (msg.method == 'redirectToSignin' && | 449 } else if (msg.method == 'redirectToSignin' && |
| 444 this.isParentMessage_(e)) { | 450 this.isParentMessage_(e)) { |
| 445 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 451 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
| 446 } else { | 452 } else { |
| 447 console.error('Authenticator.onMessage: unknown message + origin!?'); | 453 console.error('Authenticator.onMessage: unknown message + origin!?'); |
| 448 } | 454 } |
| 449 } | 455 } |
| 450 }; | 456 }; |
| 451 | 457 |
| 452 Authenticator.getInstance().initialize(); | 458 Authenticator.getInstance().initialize(); |
| OLD | NEW |