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

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

Issue 687873003: Allow the background page to get an OAuth token for apps v1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 class that handles retrieval/storage of an OAuth2 token. 7 * OAuth2 class that handles retrieval/storage of an OAuth2 token.
8 * 8 *
9 * Uses a content script to trampoline the OAuth redirect page back into the 9 * Uses a content script to trampoline the OAuth redirect page back into the
10 * extension context. This works around the lack of native support for 10 * extension context. This works around the lack of native support for
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 remoting.OAuth2.prototype.onTokens_ = 230 remoting.OAuth2.prototype.onTokens_ =
231 function(onOk, refreshToken, accessToken, expiresIn) { 231 function(onOk, refreshToken, accessToken, expiresIn) {
232 this.setAccessToken_(accessToken, expiresIn); 232 this.setAccessToken_(accessToken, expiresIn);
233 this.setRefreshToken_(refreshToken); 233 this.setRefreshToken_(refreshToken);
234 onOk(); 234 onOk();
235 }; 235 };
236 236
237 /** 237 /**
238 * Redirect page to get a new OAuth2 Refresh Token. 238 * Redirect page to get a new OAuth2 Refresh Token.
239 * 239 *
240 * @param {function():void} onDone Completion callback.
240 * @return {void} Nothing. 241 * @return {void} Nothing.
241 */ 242 */
242 remoting.OAuth2.prototype.doAuthRedirect = function() { 243 remoting.OAuth2.prototype.doAuthRedirect = function(onDone) {
243 /** @type {remoting.OAuth2} */ 244 /** @type {remoting.OAuth2} */
244 var that = this; 245 var that = this;
245 var xsrf_token = remoting.generateXsrfToken(); 246 var xsrf_token = base.generateXsrfToken();
246 window.localStorage.setItem(this.KEY_XSRF_TOKEN_, xsrf_token); 247 window.localStorage.setItem(this.KEY_XSRF_TOKEN_, xsrf_token);
247 var GET_CODE_URL = this.getOAuth2AuthEndpoint_() + '?' + 248 var GET_CODE_URL = this.getOAuth2AuthEndpoint_() + '?' +
248 remoting.xhr.urlencodeParamHash({ 249 remoting.xhr.urlencodeParamHash({
249 'client_id': this.getClientId_(), 250 'client_id': this.getClientId_(),
250 'redirect_uri': this.getRedirectUri_(), 251 'redirect_uri': this.getRedirectUri_(),
251 'scope': this.SCOPE_, 252 'scope': this.SCOPE_,
252 'state': xsrf_token, 253 'state': xsrf_token,
253 'response_type': 'code', 254 'response_type': 'code',
254 'access_type': 'offline', 255 'access_type': 'offline',
255 'approval_prompt': 'force' 256 'approval_prompt': 'force'
256 }); 257 });
257 258
258 /** 259 /**
259 * Processes the results of the oauth flow. 260 * Processes the results of the oauth flow.
260 * 261 *
261 * @param {Object.<string, string>} message Dictionary containing the parsed 262 * @param {Object.<string, string>} message Dictionary containing the parsed
262 * OAuth redirect URL parameters. 263 * OAuth redirect URL parameters.
263 */ 264 */
264 function oauth2MessageListener(message) { 265 function oauth2MessageListener(message) {
265 if ('code' in message && 'state' in message) { 266 if ('code' in message && 'state' in message) {
266 var onDone = function() {
267 window.location.reload();
268 };
269 that.exchangeCodeForToken( 267 that.exchangeCodeForToken(
270 message['code'], message['state'], onDone); 268 message['code'], message['state'], onDone);
kelvinp 2014/10/29 20:28:54 Probably need to remove onDone from line 268 as we
Jamie 2014/10/30 19:38:25 I think this is correct. We're just delegating the
kelvinp 2014/10/30 20:48:38 My bad. Face palm O_O
271 } else { 269 } else {
272 if ('error' in message) { 270 if ('error' in message) {
273 console.error( 271 console.error(
274 'Could not obtain authorization code: ' + message['error']); 272 'Could not obtain authorization code: ' + message['error']);
275 } else { 273 } else {
276 // We intentionally don't log the response - since we don't understand 274 // We intentionally don't log the response - since we don't understand
277 // it, we can't tell if it has sensitive data. 275 // it, we can't tell if it has sensitive data.
278 console.error('Invalid oauth2 response.'); 276 console.error('Invalid oauth2 response.');
279 } 277 }
280 } 278 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 * @return {?string} The email address, if it has been cached by a previous call 367 * @return {?string} The email address, if it has been cached by a previous call
370 * to getEmail, otherwise null. 368 * to getEmail, otherwise null.
371 */ 369 */
372 remoting.OAuth2.prototype.getCachedEmail = function() { 370 remoting.OAuth2.prototype.getCachedEmail = function() {
373 var value = window.localStorage.getItem(this.KEY_EMAIL_); 371 var value = window.localStorage.getItem(this.KEY_EMAIL_);
374 if (typeof value == 'string') { 372 if (typeof value == 'string') {
375 return value; 373 return value;
376 } 374 }
377 return null; 375 return null;
378 }; 376 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698