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

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: 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
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.
24 *
25 * fetchThirdPartyToken: Called when a third party authentication token
26 * is needed
27 *
28 * @typedef {{
29 * accessCode: (string|undefined),
30 * fetchPin: (function(boolean,function(string): void)|undefined),
31 * pairingInfo: (remoting.PairingInfo|undefined),
32 * fetchThirdPartyToken:
33 * (function(string ,string , string,
34 * function(string, string):void) | undefined)
35 * }}
36 */
37 remoting.CredentialsProviderParams;
38
39 /**
40 * @param {remoting.CredentialsProviderParams} args
41 * @constructor
42 */
43 remoting.CredentialsProvider = function(args) {
44 /** @private */
45 this.fetchPin_ = args.fetchPin;
46 /** @private */
47 this.pairingInfo_ = args.pairingInfo;
48 /** @private */
49 this.accessCode_ = args.accessCode;
50 /** @private */
51 this.fetchThirdPartyToken_ = args.fetchThirdPartyToken;
52 };
53
54 /** @enum {number} */
55 remoting.CredentialsProvider.Methods = {
56 THIRD_PARTY: 0,
57 PAIRING: 1,
58 ACCESS_CODE: 2,
59 PIN: 3
60 };
61
62 /**
63 * @param {remoting.CredentialsProvider.Methods} method
64 * @returns {boolean} Whether |method| is supported.
65 */
66 remoting.CredentialsProvider.prototype.supports = function(method) {
67 var Methods = remoting.CredentialsProvider.Methods;
68 if (method === Methods.PIN) {
69 return Boolean(this.fetchPin_);
70 } else if (method === Methods.ACCESS_CODE) {
71 return Boolean(this.accessCode_);
72 } else if (method === Methods.THIRD_PARTY) {
73 return Boolean(this.fetchThirdPartyToken_);
74 } else if (method === Methods.PAIRING) {
75 return Boolean(this.pairingInfo_);
76 }
77 };
78
79 /** @returns {string} The It2Me access code */
80 remoting.CredentialsProvider.prototype.getSharedSecret = function() {
81 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
82 };
83
84 /** @returns {remoting.PairingInfo} */
85 remoting.CredentialsProvider.prototype.getPairingInfo = function() {
86 return this.pairingInfo_ || { id: '', secret: ''};
87 };
88
89 /**
90 * @param {boolean} pairingSupported Whether pairing is supported by the host.
91 * @returns {Promise<string>}
92 */
93 remoting.CredentialsProvider.prototype.getPIN = function(pairingSupported) {
94 var that = this;
95 if (!this.fetchPin_) {
96 Promise.resolve('');
97 }
98 return new Promise(function(/** function(string) */ resolve) {
99 that.fetchPin_(pairingSupported, resolve);
100 });
101 };
102
103 /**
104 * @param {string} tokenUrl Token-issue URL received from the host.
105 * @param {string} hostPublicKey Host public key (DER and Base64 encoded).
106 * @param {string} scope OAuth scope to request the token for.
107 *
108 * @returns {Promise<remoting.ThirdPartyToken>}
109 */
110 remoting.CredentialsProvider.prototype.getThirdPartyToken = function(
111 tokenUrl, hostPublicKey, scope) {
112 var that = this;
113 if (!this.fetchThirdPartyToken_) {
114 Promise.resolve({token: '', secret: ''});
115 }
116 return new Promise(function(/** Function */ resolve) {
117 var onTokenFetched = function(/** string */ token, /** string */ secret) {
118 resolve({token: token, secret: secret});
119 };
120 that.fetchThirdPartyToken_(tokenUrl, hostPublicKey, scope, onTokenFetched);
121 });
122 };
123
124
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698