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
3 // found in the LICENSE file.
7 var remoting = remoting || {};
9 /** @typedef {{clientId: string, sharedSecret: string}} */
12 /** @typedef {{token: string, secret: string}} */
13 remoting.ThirdPartyToken;
16 * Parameters for the remoting.CredentialsProvider constructor.
18 * fetchPin: Called by Me2Me connections when a PIN needs to be obtained
21 * pairingInfo: The pairing info for Me2Me Connections.
23 * accessCode: It2Me access code. If present, the |fetchPin| callback will be
26 * fetchThirdPartyToken: Called when a third party authentication token
30 * accessCode: (string|undefined),
31 * fetchPin: (function(boolean,function(string): void)|undefined),
32 * pairingInfo: (remoting.PairingInfo|undefined),
33 * fetchThirdPartyToken:
34 * (function(string ,string , string,
35 * function(string, string):void) | undefined)
38 remoting.CredentialsProviderParams;
41 * @param {remoting.CredentialsProviderParams} args
44 remoting.CredentialsProvider = function(args) {
46 this.fetchPin_ = (args.accessCode) ? this.getAccessCode_ : args.fetchPin;
48 this.pairingInfo_ = args.pairingInfo;
50 this.accessCode_ = args.accessCode;
52 this.fetchThirdPartyToken_ = args.fetchThirdPartyToken;
55 /** @returns {void} */
56 remoting.CredentialsProvider.prototype.getAccessCode_ = function(
57 /** boolean */ supportsPairing, /** Function */ callback) {
58 callback(this.accessCode_);
61 /** @returns {remoting.PairingInfo} */
62 remoting.CredentialsProvider.prototype.getPairingInfo = function() {
63 return this.pairingInfo_ || { clientId: '', sharedSecret: ''};
67 * @param {boolean} pairingSupported Whether pairing is supported by the host.
68 * @returns {Promise<string>}
70 remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) {
72 if (!this.fetchPin_) {
75 return new Promise(function(/** function(string) */ resolve) {
76 that.fetchPin_(pairingSupported, resolve);
81 * @param {string} tokenUrl Token-issue URL received from the host.
82 * @param {string} hostPublicKey Host public key (DER and Base64 encoded).
83 * @param {string} scope OAuth scope to request the token for.
85 * @returns {Promise<remoting.ThirdPartyToken>}
87 remoting.CredentialsProvider.prototype.getThirdPartyToken = function(
88 tokenUrl, hostPublicKey, scope) {
90 if (!this.fetchThirdPartyToken_) {
91 Promise.resolve({token: '', secret: ''});
93 return new Promise(function(/** Function */ resolve) {
94 var onTokenFetched = function(/** string */ token, /** string */ secret) {
95 resolve({token: token, secret: secret});
97 that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched);