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

Side by Side Diff: remoting/webapp/base/js/auth_init.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: Rebase 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
« no previous file with comments | « remoting/webapp/base/js/auth_dialog.js ('k') | remoting/webapp/crd/js/activation_handler.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** 10 /**
11 * Get the user's email address and full name. 11 * Get the user's email address and full name.
12 * 12 *
13 * @param {function(string,string):void} onUserInfoAvailable Callback invoked 13 * @param {function(string,string):void} onUserInfoAvailable Callback invoked
14 * when the user's email address and full name are available. 14 * when the user's email address and full name are available.
15 * @return {void} Nothing. 15 * @return {void} Nothing.
16 */ 16 */
17 remoting.initIdentity = function(onUserInfoAvailable) { 17 remoting.initIdentity = function(onUserInfoAvailable) {
18 18
19 /**
20 * Show the authorization consent UI and register a one-shot event handler to
21 * continue the authorization process.
22 *
23 * @param {function():void} authContinue Callback to invoke when the user
24 * clicks "Continue".
25 */
26 function promptForConsent(authContinue) {
27 /** @type {HTMLElement} */
28 var dialog = document.getElementById('auth-dialog');
29 /** @type {HTMLElement} */
30 var button = document.getElementById('auth-button');
31 var consentGranted = function(event) {
32 dialog.hidden = true;
33 button.removeEventListener('click', consentGranted, false);
34 authContinue();
35 remoting.windowShape.updateClientWindowShape();
36 };
37 dialog.hidden = false;
38
39 /** @type {HTMLElement} */
40 var dialog_border = document.getElementById('auth-dialog-border');
41 remoting.authDialog = new remoting.AuthDialog(dialog_border);
42 remoting.windowShape.addCallback(remoting.authDialog);
43
44 button.addEventListener('click', consentGranted, false);
45 }
46
47 /** @param {remoting.Error} error */ 19 /** @param {remoting.Error} error */
48 function onGetIdentityInfoError(error) { 20 function onGetIdentityInfoError(error) {
49 // No need to show the error message for NOT_AUTHENTICATED 21 // No need to show the error message for NOT_AUTHENTICATED
50 // because we will show "auth-dialog". 22 // because we will show "auth-dialog".
51 if (error != remoting.Error.NOT_AUTHENTICATED) { 23 if (error != remoting.Error.NOT_AUTHENTICATED) {
52 remoting.showErrorMessage(error); 24 remoting.showErrorMessage(error);
53 } 25 }
54 } 26 }
55 27
56 if (base.isAppsV2()) { 28 if (base.isAppsV2()) {
57 remoting.identity = new remoting.Identity(promptForConsent); 29 remoting.identity =
30 new remoting.Identity(remoting.AuthDialog.getInstance());
58 } else { 31 } else {
59 // TODO(garykac) Remove this and replace with identity. 32 // TODO(garykac) Remove this and replace with identity.
60 remoting.oauth2 = new remoting.OAuth2(); 33 remoting.oauth2 = new remoting.OAuth2();
61 if (!remoting.oauth2.isAuthenticated()) { 34 var oauth2 = /** @type {*} */ (remoting.oauth2);
62 document.getElementById('auth-dialog').hidden = false; 35 remoting.identity = /** @type {remoting.Identity} */ (oauth2);
36 if (!remoting.identity.isAuthenticated()) {
37 remoting.AuthDialog.getInstance().show().then(function() {
38 remoting.oauth2.doAuthRedirect(function(){
39 window.location.reload();
40 });
41 });
63 } 42 }
64 remoting.identity = remoting.oauth2;
65 } 43 }
66 44
67 remoting.identity.getUserInfo(onUserInfoAvailable, 45 remoting.identity.getUserInfo(onUserInfoAvailable,
68 onGetIdentityInfoError); 46 onGetIdentityInfoError);
69 } 47 };
48
49 /**
50 * Removes the cached token and restarts the app.
51 *
52 * @return {void} Nothing.
53 */
54 remoting.handleAuthFailureAndRelaunch = function() {
55 remoting.identity.removeCachedAuthToken(function(){
56 if (base.isAppsV2()) {
57 base.Ipc.invoke('remoting.ActivationHandler.restart',
58 chrome.app.window.current().id);
59 } else {
60 window.location.reload();
61 }
62 });
63 };
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/auth_dialog.js ('k') | remoting/webapp/crd/js/activation_handler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698