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

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

Issue 12905012: Webapp changes to support third party authentication (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase, update patch Created 7 years, 8 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/manifest.json ('k') | remoting/webapp/plugin_settings.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 'refresh_token': this.getRefreshToken_(), 301 'refresh_token': this.getRefreshToken_(),
302 'grant_type': 'refresh_token' 302 'grant_type': 'refresh_token'
303 }; 303 };
304 304
305 remoting.xhr.post(this.getOAuth2TokenEndpoint_(), 305 remoting.xhr.post(this.getOAuth2TokenEndpoint_(),
306 this.processTokenResponse_.bind(this, onDone), 306 this.processTokenResponse_.bind(this, onDone),
307 parameters); 307 parameters);
308 }; 308 };
309 309
310 /** 310 /**
311 * @private
312 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */
313 remoting.OAuth2.prototype.generateXsrfToken_ = function() {
314 var random = new Uint8Array(16);
315 window.crypto.getRandomValues(random);
316 var base64Token = window.btoa(String.fromCharCode.apply(null, random));
317 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
318 };
319
320 /**
321 * Redirect page to get a new OAuth2 Refresh Token. 311 * Redirect page to get a new OAuth2 Refresh Token.
322 * 312 *
323 * @return {void} Nothing. 313 * @return {void} Nothing.
324 */ 314 */
325 remoting.OAuth2.prototype.doAuthRedirect = function() { 315 remoting.OAuth2.prototype.doAuthRedirect = function() {
326 var xsrf_token = this.generateXsrfToken_(); 316 var xsrf_token = remoting.generateXsrfToken();
327 window.localStorage.setItem(this.KEY_XSRF_TOKEN_, xsrf_token); 317 window.localStorage.setItem(this.KEY_XSRF_TOKEN_, xsrf_token);
328 var GET_CODE_URL = this.getOAuth2AuthEndpoint_() + '?' + 318 var GET_CODE_URL = this.getOAuth2AuthEndpoint_() + '?' +
329 remoting.xhr.urlencodeParamHash({ 319 remoting.xhr.urlencodeParamHash({
330 'client_id': this.getClientId_(), 320 'client_id': this.getClientId_(),
331 'redirect_uri': this.getRedirectUri_(), 321 'redirect_uri': this.getRedirectUri_(),
332 'scope': this.SCOPE_, 322 'scope': this.SCOPE_,
333 'state': xsrf_token, 323 'state': xsrf_token,
334 'response_type': 'code', 324 'response_type': 'code',
335 'access_type': 'offline', 325 'access_type': 'offline',
336 'approval_prompt': 'force' 326 'approval_prompt': 'force'
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 * @return {?string} The email address, if it has been cached by a previous call 513 * @return {?string} The email address, if it has been cached by a previous call
524 * to getEmail, otherwise null. 514 * to getEmail, otherwise null.
525 */ 515 */
526 remoting.OAuth2.prototype.getCachedEmail = function() { 516 remoting.OAuth2.prototype.getCachedEmail = function() {
527 var value = window.localStorage.getItem(this.KEY_EMAIL_); 517 var value = window.localStorage.getItem(this.KEY_EMAIL_);
528 if (typeof value == 'string') { 518 if (typeof value == 'string') {
529 return value; 519 return value;
530 } 520 }
531 return null; 521 return null;
532 }; 522 };
OLDNEW
« no previous file with comments | « remoting/webapp/manifest.json ('k') | remoting/webapp/plugin_settings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698