Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: remoting/webapp/crd/js/credentials_provider.js

Issue 954373002: [Webapp Refactor] Group authentications fields into remoting.CredentialsProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove supports() Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/client_session.js ('k') | remoting/webapp/crd/js/identity.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 'use strict';
6
7 var remoting = remoting || {};
8
9 /** @typedef {{id: string, secret: string}} */
10 remoting.PairingInfo;
11
12 /** @typedef {{token: string, secret: string}} */
13 remoting.ThirdPartyToken;
14
15 /**
16 * Parameters for the remoting.CredentialsProvider constructor.
17 *
18 * fetchPin: Called by Me2Me connections when a PIN needs to be obtained
19 * interactively.
20 *
21 * pairingInfo: The pairing info for Me2Me Connections.
22 *
23 * accessCode: It2Me access code. If present, the |fetchPin| callback will be
24 * ignored.
25 *
26 * fetchThirdPartyToken: Called when a third party authentication token
27 * is needed
28 *
29 * @typedef {{
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)
36 * }}
37 */
38 remoting.CredentialsProviderParams;
39
40 /**
41 * @param {remoting.CredentialsProviderParams} args
42 * @constructor
43 */
44 remoting.CredentialsProvider = function(args) {
45 /** @private */
46 this.fetchPin_ = (args.accessCode) ? this.getAccessCode_ : args.fetchPin;
Jamie 2015/02/28 00:41:12 Assert that exactly one of accessCode or fetchPin
47 /** @private */
48 this.pairingInfo_ = args.pairingInfo;
49 /** @private */
50 this.accessCode_ = args.accessCode;
51 /** @private */
52 this.fetchThirdPartyToken_ = args.fetchThirdPartyToken;
53 };
54
55 /** @returns {void} */
56 remoting.CredentialsProvider.prototype.getAccessCode_ = function(
57 /** boolean */ supportsPairing, /** Function */ callback) {
58 callback(this.accessCode_);
59 };
60
61 /** @returns {remoting.PairingInfo} */
62 remoting.CredentialsProvider.prototype.getPairingInfo = function() {
63 return this.pairingInfo_ || { id: '', secret: ''};
64 };
65
66 /**
67 * @param {boolean} pairingSupported Whether pairing is supported by the host.
68 * @returns {Promise<string>}
69 */
70 remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) {
71 var that = this;
72 if (!this.fetchPin_) {
73 Promise.resolve('');
74 }
75 return new Promise(function(/** function(string) */ resolve) {
76 that.fetchPin_(pairingSupported, resolve);
77 });
78 };
79
80 /**
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.
84 *
85 * @returns {Promise<remoting.ThirdPartyToken>}
86 */
87 remoting.CredentialsProvider.prototype.getThirdPartyToken = function(
88 tokenUrl, hostPublicKey, scope) {
89 var that = this;
90 if (!this.fetchThirdPartyToken_) {
91 Promise.resolve({token: '', secret: ''});
92 }
93 return new Promise(function(/** Function */ resolve) {
94 var onTokenFetched = function(/** string */ token, /** string */ secret) {
95 resolve({token: token, secret: secret});
96 };
97 that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched);
98 });
99 };
100
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/client_session.js ('k') | remoting/webapp/crd/js/identity.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698