Index: remoting/webapp/crd/js/credentials_provider.js |
diff --git a/remoting/webapp/crd/js/credentials_provider.js b/remoting/webapp/crd/js/credentials_provider.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..07bdcbaff8cf085c54c30b734928a79dd30c893f |
--- /dev/null |
+++ b/remoting/webapp/crd/js/credentials_provider.js |
@@ -0,0 +1,124 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+'use strict'; |
+ |
+var remoting = remoting || {}; |
+ |
+/** @typedef {{id: string, secret: string}} */ |
+remoting.PairingInfo; |
+ |
+/** @typedef {{token: string, secret: string}} */ |
+remoting.ThirdPartyToken; |
+ |
+/** |
+ * Parameters for the remoting.CredentialsProvider constructor. |
+ * |
+ * fetchPin: Called by Me2Me connections when a PIN needs to be obtained |
+ * interactively. |
+ * |
+ * pairingInfo: The pairing info for Me2Me Connections. |
+ * |
+ * accessCode: It2Me access code. |
+ * |
+ * fetchThirdPartyToken: Called when a third party authentication token |
+ * is needed |
+ * |
+ * @typedef {{ |
+ * accessCode: (string|undefined), |
+ * fetchPin: (function(boolean,function(string): void)|undefined), |
+ * pairingInfo: (remoting.PairingInfo|undefined), |
+ * fetchThirdPartyToken: |
+ * (function(string ,string , string, |
+ * function(string, string):void) | undefined) |
+ * }} |
+ */ |
+remoting.CredentialsProviderParams; |
+ |
+/** |
+ * @param {remoting.CredentialsProviderParams} args |
+ * @constructor |
+ */ |
+remoting.CredentialsProvider = function(args) { |
+ /** @private */ |
+ this.fetchPin_ = args.fetchPin; |
+ /** @private */ |
+ this.pairingInfo_ = args.pairingInfo; |
+ /** @private */ |
+ this.accessCode_ = args.accessCode; |
+ /** @private */ |
+ this.fetchThirdPartyToken_ = args.fetchThirdPartyToken; |
+}; |
+ |
+/** @enum {number} */ |
+remoting.CredentialsProvider.Methods = { |
+ THIRD_PARTY: 0, |
+ PAIRING: 1, |
+ ACCESS_CODE: 2, |
+ PIN: 3 |
+}; |
+ |
+/** |
+ * @param {remoting.CredentialsProvider.Methods} method |
+ * @returns {boolean} Whether |method| is supported. |
+ */ |
+remoting.CredentialsProvider.prototype.supports = function(method) { |
+ var Methods = remoting.CredentialsProvider.Methods; |
+ if (method === Methods.PIN) { |
+ return Boolean(this.fetchPin_); |
+ } else if (method === Methods.ACCESS_CODE) { |
+ return Boolean(this.accessCode_); |
+ } else if (method === Methods.THIRD_PARTY) { |
+ return Boolean(this.fetchThirdPartyToken_); |
+ } else if (method === Methods.PAIRING) { |
+ return Boolean(this.pairingInfo_); |
+ } |
+}; |
+ |
+/** @returns {string} The It2Me access code */ |
+remoting.CredentialsProvider.prototype.getSharedSecret = function() { |
+ return this.accessCode_ || ''; |
Jamie
2015/02/26 23:20:14
Would an assert(supports(ACCESS_CODE)) be appropri
kelvinp
2015/02/27 01:03:21
Yes, will use AccessCode instead?
No, the problem
Jamie
2015/02/27 01:53:03
Maybe a better way of phrasing it would be to ask
kelvinp
2015/02/27 19:47:40
Agreed. As discussed, this is due to the fact tha
|
+}; |
+ |
+/** @returns {remoting.PairingInfo} */ |
+remoting.CredentialsProvider.prototype.getPairingInfo = function() { |
+ return this.pairingInfo_ || { id: '', secret: ''}; |
+}; |
+ |
+/** |
+ * @param {boolean} pairingSupported Whether pairing is supported by the host. |
+ * @returns {Promise<string>} |
+ */ |
+remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) { |
+ var that = this; |
+ if (!this.fetchPin_) { |
+ Promise.resolve(''); |
+ } |
+ return new Promise(function(/** function(string) */ resolve) { |
+ that.fetchPin_(pairingSupported, resolve); |
+ }); |
+}; |
+ |
+/** |
+ * @param {string} tokenUrl Token-issue URL received from the host. |
+ * @param {string} hostPublicKey Host public key (DER and Base64 encoded). |
+ * @param {string} scope OAuth scope to request the token for. |
+ * |
+ * @returns {Promise<remoting.ThirdPartyToken>} |
+ */ |
+remoting.CredentialsProvider.prototype.getThirdPartyToken = function( |
+ tokenUrl, hostPublicKey, scope) { |
+ var that = this; |
+ if (!this.fetchThirdPartyToken_) { |
+ Promise.resolve({token: '', secret: ''}); |
+ } |
+ return new Promise(function(/** Function */ resolve) { |
+ var onTokenFetched = function(/** string */ token, /** string */ secret) { |
+ resolve({token: token, secret: secret}); |
+ }; |
+ that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched); |
+ }); |
+}; |
+ |
+ |