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

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

Issue 803653004: Update Chromoting to use /third_party/closure_compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * OAuth2 API flow implementations. 7 * OAuth2 API flow implementations.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 onDone, onError, clientId, clientSecret, refreshToken) { 72 onDone, onError, clientId, clientSecret, refreshToken) {
73 /** @param {XMLHttpRequest} xhr */ 73 /** @param {XMLHttpRequest} xhr */
74 var onResponse = function(xhr) { 74 var onResponse = function(xhr) {
75 if (xhr.status == 200) { 75 if (xhr.status == 200) {
76 try { 76 try {
77 // Don't use base.jsonParseSafe here unless you also include base.js, 77 // Don't use base.jsonParseSafe here unless you also include base.js,
78 // otherwise this won't work from the OAuth trampoline. 78 // otherwise this won't work from the OAuth trampoline.
79 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. 79 // TODO(jamiewalch): Fix this once we're no longer using the trampoline.
80 var tokens = JSON.parse(xhr.responseText); 80 var tokens = JSON.parse(xhr.responseText);
81 onDone(tokens['access_token'], tokens['expires_in']); 81 onDone(tokens['access_token'], tokens['expires_in']);
82 } catch (err) { 82 } catch (/** @type {*} */ err) {
83 console.error('Invalid "token" response from server:', 83 console.error('Invalid "token" response from server:', err);
84 /** @type {*} */ (err));
85 onError(remoting.Error.UNEXPECTED); 84 onError(remoting.Error.UNEXPECTED);
86 } 85 }
87 } else { 86 } else {
88 console.error('Failed to refresh token. Status: ' + xhr.status + 87 console.error('Failed to refresh token. Status: ' + xhr.status +
89 ' response: ' + xhr.responseText); 88 ' response: ' + xhr.responseText);
90 onError(remoting.Error.fromHttpError(xhr.status)); 89 onError(remoting.Error.fromHttpError(xhr.status));
91 } 90 }
92 }; 91 };
93 92
94 var parameters = { 93 var parameters = {
(...skipping 25 matching lines...) Expand all
120 /** @param {XMLHttpRequest} xhr */ 119 /** @param {XMLHttpRequest} xhr */
121 var onResponse = function(xhr) { 120 var onResponse = function(xhr) {
122 if (xhr.status == 200) { 121 if (xhr.status == 200) {
123 try { 122 try {
124 // Don't use base.jsonParseSafe here unless you also include base.js, 123 // Don't use base.jsonParseSafe here unless you also include base.js,
125 // otherwise this won't work from the OAuth trampoline. 124 // otherwise this won't work from the OAuth trampoline.
126 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. 125 // TODO(jamiewalch): Fix this once we're no longer using the trampoline.
127 var tokens = JSON.parse(xhr.responseText); 126 var tokens = JSON.parse(xhr.responseText);
128 onDone(tokens['refresh_token'], 127 onDone(tokens['refresh_token'],
129 tokens['access_token'], tokens['expires_in']); 128 tokens['access_token'], tokens['expires_in']);
130 } catch (err) { 129 } catch (/** @type {*} */ err) {
131 console.error('Invalid "token" response from server:', 130 console.error('Invalid "token" response from server:', err);
132 /** @type {*} */ (err));
133 onError(remoting.Error.UNEXPECTED); 131 onError(remoting.Error.UNEXPECTED);
134 } 132 }
135 } else { 133 } else {
136 console.error('Failed to exchange code for token. Status: ' + xhr.status + 134 console.error('Failed to exchange code for token. Status: ' + xhr.status +
137 ' response: ' + xhr.responseText); 135 ' response: ' + xhr.responseText);
138 onError(remoting.Error.fromHttpError(xhr.status)); 136 onError(remoting.Error.fromHttpError(xhr.status));
139 } 137 }
140 }; 138 };
141 139
142 var parameters = { 140 var parameters = {
(...skipping 16 matching lines...) Expand all
159 * @param {string} token Access token. 157 * @param {string} token Access token.
160 * @return {void} Nothing. 158 * @return {void} Nothing.
161 */ 159 */
162 remoting.OAuth2Api.prototype.getEmail = function(onDone, onError, token) { 160 remoting.OAuth2Api.prototype.getEmail = function(onDone, onError, token) {
163 /** @param {XMLHttpRequest} xhr */ 161 /** @param {XMLHttpRequest} xhr */
164 var onResponse = function(xhr) { 162 var onResponse = function(xhr) {
165 if (xhr.status == 200) { 163 if (xhr.status == 200) {
166 try { 164 try {
167 var result = JSON.parse(xhr.responseText); 165 var result = JSON.parse(xhr.responseText);
168 onDone(result['email']); 166 onDone(result['email']);
169 } catch (err) { 167 } catch (/** @type {*} */ err) {
170 console.error('Invalid "userinfo" response from server:', 168 console.error('Invalid "userinfo" response from server:', err);
171 /** @type {*} */ (err));
172 onError(remoting.Error.UNEXPECTED); 169 onError(remoting.Error.UNEXPECTED);
173 } 170 }
174 } else { 171 } else {
175 console.error('Failed to get email. Status: ' + xhr.status + 172 console.error('Failed to get email. Status: ' + xhr.status +
176 ' response: ' + xhr.responseText); 173 ' response: ' + xhr.responseText);
177 onError(remoting.Error.fromHttpError(xhr.status)); 174 onError(remoting.Error.fromHttpError(xhr.status));
178 } 175 }
179 }; 176 };
180 var headers = { 'Authorization': 'OAuth ' + token }; 177 var headers = { 'Authorization': 'OAuth ' + token };
181 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), 178 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(),
(...skipping 10 matching lines...) Expand all
192 * @param {string} token Access token. 189 * @param {string} token Access token.
193 * @return {void} Nothing. 190 * @return {void} Nothing.
194 */ 191 */
195 remoting.OAuth2Api.prototype.getUserInfo = function(onDone, onError, token) { 192 remoting.OAuth2Api.prototype.getUserInfo = function(onDone, onError, token) {
196 /** @param {XMLHttpRequest} xhr */ 193 /** @param {XMLHttpRequest} xhr */
197 var onResponse = function(xhr) { 194 var onResponse = function(xhr) {
198 if (xhr.status == 200) { 195 if (xhr.status == 200) {
199 try { 196 try {
200 var result = JSON.parse(xhr.responseText); 197 var result = JSON.parse(xhr.responseText);
201 onDone(result['email'], result['name']); 198 onDone(result['email'], result['name']);
202 } catch (err) { 199 } catch (/** @type {*} */ err) {
203 console.error('Invalid "userinfo" response from server:', 200 console.error('Invalid "userinfo" response from server:', err);
204 /** @type {*} */ (err));
205 onError(remoting.Error.UNEXPECTED); 201 onError(remoting.Error.UNEXPECTED);
206 } 202 }
207 } else { 203 } else {
208 console.error('Failed to get user info. Status: ' + xhr.status + 204 console.error('Failed to get user info. Status: ' + xhr.status +
209 ' response: ' + xhr.responseText); 205 ' response: ' + xhr.responseText);
210 onError(remoting.Error.fromHttpError(xhr.status)); 206 onError(remoting.Error.fromHttpError(xhr.status));
211 } 207 }
212 }; 208 };
213 var headers = { 'Authorization': 'OAuth ' + token }; 209 var headers = { 'Authorization': 'OAuth ' + token };
214 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), 210 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(),
215 onResponse, '', headers); 211 onResponse, '', headers);
216 }; 212 };
217 213
218 /** @type {remoting.OAuth2Api} */ 214 /** @type {remoting.OAuth2Api} */
219 remoting.oauth2Api = new remoting.OAuth2Api(); 215 remoting.oauth2Api = new remoting.OAuth2Api();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698