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

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

Issue 868203002: Handle authentication failures in the v2 app by restarting the app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer's feedback Created 5 years, 10 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 (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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 chrome.extension.onMessage.removeListener(oauth2MessageListener); 285 chrome.extension.onMessage.removeListener(oauth2MessageListener);
286 sendResponse(null); 286 sendResponse(null);
287 } 287 }
288 chrome.extension.onMessage.addListener(oauth2MessageListener); 288 chrome.extension.onMessage.addListener(oauth2MessageListener);
289 window.open(GET_CODE_URL, '_blank', 'location=yes,toolbar=no,menubar=no'); 289 window.open(GET_CODE_URL, '_blank', 'location=yes,toolbar=no,menubar=no');
290 }; 290 };
291 291
292 /** 292 /**
293 * Redirect page to get a new OAuth Refresh Token. 293 * Redirect page to get a new OAuth Refresh Token.
294 * 294 *
295 * @param {function():void} onDone Completion callback. 295 * @return {Promise} A promise that resolves when the token is received.
296 * @return {void} Nothing.
297 */ 296 */
298 remoting.OAuth2.prototype.doAuthRedirect = function(onDone) { 297 remoting.OAuth2.prototype.handleAuthFailure = function() {
298 var deferred = new base.Deferred();
299
299 /** @type {remoting.OAuth2} */ 300 /** @type {remoting.OAuth2} */
300 var that = this; 301 var that = this;
301 /** @param {?string} code */ 302 /** @param {?string} code */
302 var onAuthorizationCode = function(code) { 303 var onAuthorizationCode = function(code) {
303 if (code) { 304 if (code) {
304 that.exchangeCodeForToken(code, onDone); 305 that.exchangeCodeForToken(code, deferred.resolve.bind(deferred));
305 } else { 306 } else {
306 onDone(); 307 deferred.reject(remoting.Error.NOT_AUTHENTICATED);
307 } 308 }
308 }; 309 };
309 this.getAuthorizationCode(onAuthorizationCode); 310 this.getAuthorizationCode(onAuthorizationCode);
311
312 return deferred.promise();
310 }; 313 };
311 314
312 /** 315 /**
316 * Removes the cached token, prompts the user to get the new token and
317 * relaunches the current window.
318 * @return {void} Nothing.
319 */
320 remoting.OAuth2.prototype.handleAuthFailureAndRelaunch = function() {
321 this.handleAuthFailure().then(function() {
322 window.location.reload();
323 });
324 };
325
326 /**
313 * Asynchronously exchanges an authorization code for a refresh token. 327 * Asynchronously exchanges an authorization code for a refresh token.
314 * 328 *
315 * @param {string} code The OAuth2 authorization code. 329 * @param {string} code The OAuth2 authorization code.
316 * @param {function():void} onDone Callback to invoke on completion. 330 * @param {function():void} onDone Callback to invoke on completion.
317 * @return {void} Nothing. 331 * @return {void} Nothing.
318 */ 332 */
319 remoting.OAuth2.prototype.exchangeCodeForToken = function(code, onDone) { 333 remoting.OAuth2.prototype.exchangeCodeForToken = function(code, onDone) {
320 /** @param {remoting.Error} error */ 334 /** @param {remoting.Error} error */
321 var onError = function(error) { 335 var onError = function(error) {
322 console.error('Unable to exchange code for token: ', error); 336 console.error('Unable to exchange code for token: ', error);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 * @return {?string} The user's full name, if it has been cached by a previous 471 * @return {?string} The user's full name, if it has been cached by a previous
458 * call to getUserInfo, otherwise null. 472 * call to getUserInfo, otherwise null.
459 */ 473 */
460 remoting.OAuth2.prototype.getCachedUserFullName = function() { 474 remoting.OAuth2.prototype.getCachedUserFullName = function() {
461 var value = window.localStorage.getItem(this.KEY_FULLNAME_); 475 var value = window.localStorage.getItem(this.KEY_FULLNAME_);
462 if (typeof value == 'string') { 476 if (typeof value == 'string') {
463 return value; 477 return value;
464 } 478 }
465 return null; 479 return null;
466 }; 480 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698