| 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 |
| 11 /** | 11 /** |
| 12 * Gaia auth extension url origin. | 12 * Gaia auth extension url origin. |
| 13 * @type {string} | 13 * @type {string} |
| 14 */ | 14 */ |
| 15 Authenticator.THIS_EXTENSION_ORIGIN = | 15 Authenticator.THIS_EXTENSION_ORIGIN = |
| 16 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik'; | 16 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik'; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * The lowest version of the credentials passing API supported. | 19 * The lowest version of the credentials passing API supported. |
| 20 * @type {number} | 20 * @type {number} |
| 21 */ | 21 */ |
| 22 Authenticator.MIN_API_VERSION_VERSION = 1; | 22 Authenticator.MIN_API_VERSION_VERSION = 1; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * The highest version of the credentials passing API supported. | 25 * The highest version of the credentials passing API supported. |
| 26 * @type {number} | 26 * @type {number} |
| 27 */ | 27 */ |
| 28 Authenticator.MAX_API_VERSION_VERSION = 2; | 28 Authenticator.MAX_API_VERSION_VERSION = 1; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * The key types supported for credentials passing API 2 and higher. | 31 * The key types supported by the credentials passing API. |
| 32 * @type {Array} Array of strings. | 32 * @type {Array} Array of strings. |
| 33 */ | 33 */ |
| 34 Authenticator.API_KEY_TYPES = [ | 34 Authenticator.API_KEY_TYPES = [ |
| 35 'KEY_TYPE_PASSWORD_PLAIN', | 35 'KEY_TYPE_PASSWORD_PLAIN', |
| 36 ]; | 36 ]; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Singleton getter of Authenticator. | 39 * Singleton getter of Authenticator. |
| 40 * @return {Object} The singleton instance of Authenticator. | 40 * @return {Object} The singleton instance of Authenticator. |
| 41 */ | 41 */ |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 }, | 285 }, |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * Invoked when one of the credential passing API methods is called by a SAML | 288 * Invoked when one of the credential passing API methods is called by a SAML |
| 289 * provider. | 289 * provider. |
| 290 * @param {!Object} msg Details of the API call. | 290 * @param {!Object} msg Details of the API call. |
| 291 */ | 291 */ |
| 292 onAPICall_: function(msg) { | 292 onAPICall_: function(msg) { |
| 293 var call = msg.call; | 293 var call = msg.call; |
| 294 if (call.method == 'initialize') { | 294 if (call.method == 'initialize') { |
| 295 // TODO(bartfab): There was no |requestedVersion| parameter in version 1 | |
| 296 // of the API. Remove this code once all consumers have switched to | |
| 297 // version 2 or higher. | |
| 298 if (!call.hasOwnProperty('requestedVersion')) { | |
| 299 if (Authenticator.MIN_API_VERSION_VERSION == 1) { | |
| 300 this.apiVersion_ = 1; | |
| 301 this.initialized_ = true; | |
| 302 this.sendInitializationSuccess_(); | |
| 303 } | |
| 304 // The glue code for API version 1 interprets all responses as success. | |
| 305 // Instead of reporting failure, do not send any response at all. | |
| 306 return; | |
| 307 } | |
| 308 | |
| 309 if (!Number.isInteger(call.requestedVersion) || | 295 if (!Number.isInteger(call.requestedVersion) || |
| 310 call.requestedVersion < Authenticator.MIN_API_VERSION_VERSION) { | 296 call.requestedVersion < Authenticator.MIN_API_VERSION_VERSION) { |
| 311 this.sendInitializationFailure_(); | 297 this.sendInitializationFailure_(); |
| 312 return; | 298 return; |
| 313 } | 299 } |
| 314 | 300 |
| 315 this.apiVersion_ = Math.min(call.requestedVersion, | 301 this.apiVersion_ = Math.min(call.requestedVersion, |
| 316 Authenticator.MAX_API_VERSION_VERSION); | 302 Authenticator.MAX_API_VERSION_VERSION); |
| 317 this.initialized_ = true; | 303 this.initialized_ = true; |
| 318 this.sendInitializationSuccess_(); | 304 this.sendInitializationSuccess_(); |
| 319 return; | 305 return; |
| 320 } | 306 } |
| 321 | 307 |
| 322 if (call.method == 'add') { | 308 if (call.method == 'add') { |
| 323 if (this.apiVersion_ > 1 && | 309 if (Authenticator.API_KEY_TYPES.indexOf(call.keyType) == -1) { |
| 324 Authenticator.API_KEY_TYPES.indexOf(call.keyType) == -1) { | |
| 325 console.error('Authenticator.onAPICall_: unsupported key type'); | 310 console.error('Authenticator.onAPICall_: unsupported key type'); |
| 326 return; | 311 return; |
| 327 } | 312 } |
| 328 this.apiToken_ = call.token; | 313 this.apiToken_ = call.token; |
| 329 this.email_ = call.user; | 314 this.email_ = call.user; |
| 330 if (this.apiVersion_ == 1) | 315 this.passwordBytes_ = call.passwordBytes; |
| 331 this.passwordBytes_ = call.password; | |
| 332 else | |
| 333 this.passwordBytes_ = call.passwordBytes; | |
| 334 } else if (call.method == 'confirm') { | 316 } else if (call.method == 'confirm') { |
| 335 if (call.token != this.apiToken_) | 317 if (call.token != this.apiToken_) |
| 336 console.error('Authenticator.onAPICall_: token mismatch'); | 318 console.error('Authenticator.onAPICall_: token mismatch'); |
| 337 } else { | 319 } else { |
| 338 console.error('Authenticator.onAPICall_: unknown message'); | 320 console.error('Authenticator.onAPICall_: unknown message'); |
| 339 } | 321 } |
| 340 }, | 322 }, |
| 341 | 323 |
| 342 sendInitializationSuccess_: function() { | 324 sendInitializationSuccess_: function() { |
| 343 var response = { | 325 this.supportChannel_.send({name: 'apiResponse', response: { |
| 344 result: 'initialized', | 326 result: 'initialized', |
| 345 version: this.apiVersion_ | 327 version: this.apiVersion_, |
| 346 }; | 328 keyTypes: Authenticator.API_KEY_TYPES |
| 347 if (this.apiVersion_ >= 2) | 329 }}); |
| 348 response['keyTypes'] = Authenticator.API_KEY_TYPES; | |
| 349 | |
| 350 this.supportChannel_.send({name: 'apiResponse', response: response}); | |
| 351 }, | 330 }, |
| 352 | 331 |
| 353 sendInitializationFailure_: function() { | 332 sendInitializationFailure_: function() { |
| 354 this.supportChannel_.send({ | 333 this.supportChannel_.send({ |
| 355 name: 'apiResponse', | 334 name: 'apiResponse', |
| 356 response: {result: 'initialization_failed'} | 335 response: {result: 'initialization_failed'} |
| 357 }); | 336 }); |
| 358 }, | 337 }, |
| 359 | 338 |
| 360 onConfirmLogin_: function() { | 339 onConfirmLogin_: function() { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } else if (msg.method == 'redirectToSignin' && | 427 } else if (msg.method == 'redirectToSignin' && |
| 449 this.isParentMessage_(e)) { | 428 this.isParentMessage_(e)) { |
| 450 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 429 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
| 451 } else { | 430 } else { |
| 452 console.error('Authenticator.onMessage: unknown message + origin!?'); | 431 console.error('Authenticator.onMessage: unknown message + origin!?'); |
| 453 } | 432 } |
| 454 } | 433 } |
| 455 }; | 434 }; |
| 456 | 435 |
| 457 Authenticator.getInstance().initialize(); | 436 Authenticator.getInstance().initialize(); |
| OLD | NEW |