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 153 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() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 passwordCount: passwords.length}, | 374 passwordCount: passwords.length}, |
371 this.parentPage_); | 375 this.parentPage_); |
372 } | 376 } |
373 }.bind(this)); | 377 }.bind(this)); |
374 } | 378 } |
375 }, | 379 }, |
376 | 380 |
377 maybeCompleteSAMLLogin_: function() { | 381 maybeCompleteSAMLLogin_: function() { |
378 // SAML login is complete when the user's e-mail address has been retrieved | 382 // 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. | 383 // from GAIA and the user has successfully confirmed the password. |
380 if (this.email_ !== null && this.passwordBytes_ !== null) | 384 if (this.email_ !== null && this.gaiaId_ !== null && |
385 this.passwordBytes_ !== null) { | |
381 this.completeLogin_(); | 386 this.completeLogin_(); |
387 } | |
382 }, | 388 }, |
383 | 389 |
384 onVerifyConfirmedPassword_: function(password) { | 390 onVerifyConfirmedPassword_: function(password) { |
385 this.supportChannel_.sendWithCallback( | 391 this.supportChannel_.sendWithCallback( |
386 {name: 'getScrapedPasswords'}, | 392 {name: 'getScrapedPasswords'}, |
387 function(passwords) { | 393 function(passwords) { |
388 for (var i = 0; i < passwords.length; ++i) { | 394 for (var i = 0; i < passwords.length; ++i) { |
389 if (passwords[i] == password) { | 395 if (passwords[i] == password) { |
390 this.passwordBytes_ = passwords[i]; | 396 this.passwordBytes_ = passwords[i]; |
391 this.maybeCompleteSAMLLogin_(); | 397 this.maybeCompleteSAMLLogin_(); |
392 return; | 398 return; |
393 } | 399 } |
394 } | 400 } |
395 window.parent.postMessage( | 401 window.parent.postMessage( |
396 {method: 'confirmPassword', email: this.email_}, | 402 {method: 'confirmPassword', email: this.email_}, |
397 this.parentPage_); | 403 this.parentPage_); |
398 }.bind(this)); | 404 }.bind(this)); |
399 }, | 405 }, |
400 | 406 |
401 onMessage: function(e) { | 407 onMessage: function(e) { |
402 var msg = e.data; | 408 var msg = e.data; |
403 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { | 409 if (msg.method == 'attemptLogin' && this.isGaiaMessage_(e)) { |
404 this.email_ = msg.email; | 410 this.email_ = msg.email; |
411 this.gaiaId_ = msg.gaiaId; | |
xiyuan
2014/09/22 21:48:56
This does not work for cros login. 'attemptLogin'
Roger Tawa OOO till Jul 10th
2014/09/23 19:43:42
Done.
| |
405 this.passwordBytes_ = msg.password; | 412 this.passwordBytes_ = msg.password; |
406 this.attemptToken_ = msg.attemptToken; | 413 this.attemptToken_ = msg.attemptToken; |
407 this.chooseWhatToSync_ = msg.chooseWhatToSync; | 414 this.chooseWhatToSync_ = msg.chooseWhatToSync; |
408 this.isSAMLFlow_ = false; | 415 this.isSAMLFlow_ = false; |
409 if (this.supportChannel_) | 416 if (this.supportChannel_) |
410 this.supportChannel_.send({name: 'startAuth'}); | 417 this.supportChannel_.send({name: 'startAuth'}); |
411 else | 418 else |
412 console.error('Support channel is not initialized.'); | 419 console.error('Support channel is not initialized.'); |
413 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { | 420 } else if (msg.method == 'clearOldAttempts' && this.isGaiaMessage_(e)) { |
414 if (!this.gaiaLoaded_) { | 421 if (!this.gaiaLoaded_) { |
415 this.gaiaLoaded_ = true; | 422 this.gaiaLoaded_ = true; |
416 this.maybeInitialized_(); | 423 this.maybeInitialized_(); |
417 } | 424 } |
418 this.email_ = null; | 425 this.email_ = null; |
426 this.gaiaId_ = null; | |
419 this.passwordBytes_ = null; | 427 this.passwordBytes_ = null; |
420 this.attemptToken_ = null; | 428 this.attemptToken_ = null; |
421 this.isSAMLFlow_ = false; | 429 this.isSAMLFlow_ = false; |
422 if (this.supportChannel_) | 430 if (this.supportChannel_) |
423 this.supportChannel_.send({name: 'resetAuth'}); | 431 this.supportChannel_.send({name: 'resetAuth'}); |
424 } else if (msg.method == 'setAuthenticatedUserEmail' && | 432 } else if (msg.method == 'setAuthenticatedUserEmail' && |
425 this.isParentMessage_(e)) { | 433 this.isParentMessage_(e)) { |
426 if (this.attemptToken_ == msg.attemptToken) { | 434 if (this.attemptToken_ == msg.attemptToken) { |
427 this.email_ = msg.email; | 435 this.email_ = msg.email; |
436 this.gaiaId_ = msg.gaiaId; | |
xiyuan
2014/09/22 21:48:56
This probably does not work either. 'setAuthentica
Roger Tawa OOO till Jul 10th
2014/09/23 19:43:43
Done.
| |
428 this.maybeCompleteSAMLLogin_(); | 437 this.maybeCompleteSAMLLogin_(); |
429 } | 438 } |
430 } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { | 439 } else if (msg.method == 'confirmLogin' && this.isInternalMessage_(e)) { |
431 // In the desktop mode, Chrome needs to wait for extra info such as | 440 // In the desktop mode, Chrome needs to wait for extra info such as |
432 // session index from the background JS. | 441 // session index from the background JS. |
433 if (this.desktopMode_) | 442 if (this.desktopMode_) |
434 return; | 443 return; |
435 | 444 |
436 if (this.attemptToken_ == msg.attemptToken) | 445 if (this.attemptToken_ == msg.attemptToken) |
437 this.onConfirmLogin_(); | 446 this.onConfirmLogin_(); |
xiyuan
2014/09/22 21:48:56
This needs to be patched to defer until gaiaId is
Roger Tawa OOO till Jul 10th
2014/09/23 19:43:43
Done.
| |
438 else | 447 else |
439 console.error('Authenticator.onMessage: unexpected attemptToken!?'); | 448 console.error('Authenticator.onMessage: unexpected attemptToken!?'); |
440 } else if (msg.method == 'verifyConfirmedPassword' && | 449 } else if (msg.method == 'verifyConfirmedPassword' && |
441 this.isParentMessage_(e)) { | 450 this.isParentMessage_(e)) { |
442 this.onVerifyConfirmedPassword_(msg.password); | 451 this.onVerifyConfirmedPassword_(msg.password); |
443 } else if (msg.method == 'redirectToSignin' && | 452 } else if (msg.method == 'redirectToSignin' && |
444 this.isParentMessage_(e)) { | 453 this.isParentMessage_(e)) { |
445 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 454 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
446 } else { | 455 } else { |
447 console.error('Authenticator.onMessage: unknown message + origin!?'); | 456 console.error('Authenticator.onMessage: unknown message + origin!?'); |
448 } | 457 } |
449 } | 458 } |
450 }; | 459 }; |
451 | 460 |
452 Authenticator.getInstance().initialize(); | 461 Authenticator.getInstance().initialize(); |
OLD | NEW |