Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 var remoting = remoting || {}; | 7 var remoting = remoting || {}; |
| 8 | 8 |
| 9 /** @typedef {{clientId: string, sharedSecret: string}} */ | 9 /** @typedef {{clientId: string, sharedSecret: string}} */ |
| 10 remoting.PairingInfo; | 10 remoting.PairingInfo; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 */ | 43 */ |
| 44 remoting.CredentialsProvider = function(args) { | 44 remoting.CredentialsProvider = function(args) { |
| 45 /** @private */ | 45 /** @private */ |
| 46 this.fetchPin_ = (args.accessCode) ? this.getAccessCode_ : args.fetchPin; | 46 this.fetchPin_ = (args.accessCode) ? this.getAccessCode_ : args.fetchPin; |
| 47 /** @private */ | 47 /** @private */ |
| 48 this.pairingInfo_ = args.pairingInfo; | 48 this.pairingInfo_ = args.pairingInfo; |
| 49 /** @private */ | 49 /** @private */ |
| 50 this.accessCode_ = args.accessCode; | 50 this.accessCode_ = args.accessCode; |
| 51 /** @private */ | 51 /** @private */ |
| 52 this.fetchThirdPartyToken_ = args.fetchThirdPartyToken; | 52 this.fetchThirdPartyToken_ = args.fetchThirdPartyToken; |
| 53 | |
| 54 /** @private {?remoting.ChromotingEvent.AuthMethod} */ | |
| 55 this.authMethod_ = null; | |
| 53 }; | 56 }; |
| 54 | 57 |
| 55 /** @returns {void} */ | 58 /** @returns {void} */ |
| 56 remoting.CredentialsProvider.prototype.getAccessCode_ = function( | 59 remoting.CredentialsProvider.prototype.getAccessCode_ = function( |
| 57 /** boolean */ supportsPairing, /** Function */ callback) { | 60 /** boolean */ supportsPairing, /** Function */ callback) { |
| 61 this.authMethod_ = remoting.ChromotingEvent.AuthMethod.ACCESS_CODE; | |
|
Jamie
2015/10/08 22:22:42
This isn't the right place to set this. Aside from
kelvinp
2015/10/09 00:45:41
I agree that the correct long term fix will be in
Jamie
2015/10/09 01:17:21
Agreed, thanks for investigating.
kelvinp
2015/10/09 18:00:34
Done.
| |
| 58 callback(this.accessCode_); | 62 callback(this.accessCode_); |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 /** @returns {remoting.PairingInfo} */ | 65 /** @returns {remoting.PairingInfo} */ |
| 62 remoting.CredentialsProvider.prototype.getPairingInfo = function() { | 66 remoting.CredentialsProvider.prototype.getPairingInfo = function() { |
| 67 if (this.pairingInfo_) { | |
| 68 this.authMethod_ = remoting.ChromotingEvent.AuthMethod.PINLESS; | |
| 69 } | |
| 63 return this.pairingInfo_ || { clientId: '', sharedSecret: ''}; | 70 return this.pairingInfo_ || { clientId: '', sharedSecret: ''}; |
| 64 }; | 71 }; |
| 65 | 72 |
| 66 /** | 73 /** |
| 67 * @param {boolean} pairingSupported Whether pairing is supported by the host. | 74 * @param {boolean} pairingSupported Whether pairing is supported by the host. |
| 68 * @returns {Promise<string>} | 75 * @returns {Promise<string>} |
| 69 */ | 76 */ |
| 70 remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) { | 77 remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) { |
| 71 var that = this; | 78 var that = this; |
| 72 if (!this.fetchPin_) { | 79 if (!this.fetchPin_) { |
| 73 Promise.resolve(''); | 80 Promise.resolve(''); |
| 74 } | 81 } |
| 82 | |
| 83 this.authMethod_ = remoting.ChromotingEvent.AuthMethod.PIN; | |
| 75 return new Promise(function(/** function(string) */ resolve) { | 84 return new Promise(function(/** function(string) */ resolve) { |
| 76 that.fetchPin_(pairingSupported, resolve); | 85 that.fetchPin_(pairingSupported, resolve); |
| 77 }); | 86 }); |
| 78 }; | 87 }; |
| 79 | 88 |
| 80 /** | 89 /** |
| 81 * @param {string} tokenUrl Token-issue URL received from the host. | 90 * @param {string} tokenUrl Token-issue URL received from the host. |
| 82 * @param {string} hostPublicKey Host public key (DER and Base64 encoded). | 91 * @param {string} hostPublicKey Host public key (DER and Base64 encoded). |
| 83 * @param {string} scope OAuth scope to request the token for. | 92 * @param {string} scope OAuth scope to request the token for. |
| 84 * | 93 * |
| 85 * @returns {Promise<remoting.ThirdPartyToken>} | 94 * @returns {Promise<remoting.ThirdPartyToken>} |
| 86 */ | 95 */ |
| 87 remoting.CredentialsProvider.prototype.getThirdPartyToken = function( | 96 remoting.CredentialsProvider.prototype.getThirdPartyToken = function( |
| 88 tokenUrl, hostPublicKey, scope) { | 97 tokenUrl, hostPublicKey, scope) { |
| 89 var that = this; | 98 var that = this; |
| 90 if (!this.fetchThirdPartyToken_) { | 99 if (!this.fetchThirdPartyToken_) { |
| 91 Promise.resolve({token: '', secret: ''}); | 100 Promise.resolve({token: '', secret: ''}); |
| 92 } | 101 } |
| 102 | |
| 103 this.authMethod_ = remoting.ChromotingEvent.AuthMethod.THIRD_PARTY; | |
| 93 return new Promise(function(/** Function */ resolve) { | 104 return new Promise(function(/** Function */ resolve) { |
| 94 var onTokenFetched = function(/** string */ token, /** string */ secret) { | 105 var onTokenFetched = function(/** string */ token, /** string */ secret) { |
| 95 resolve({token: token, secret: secret}); | 106 resolve({token: token, secret: secret}); |
| 96 }; | 107 }; |
| 97 that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched); | 108 that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched); |
| 98 }); | 109 }); |
| 99 }; | 110 }; |
| 111 | |
| 112 /** @return {?remoting.ChromotingEvent.AuthMethod} */ | |
| 113 remoting.CredentialsProvider.prototype.getAuthMethod = function() { | |
| 114 return this.authMethod_; | |
| 115 }; | |
| OLD | NEW |