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
3 // found in the LICENSE file.
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
11 * Initialize the identity and authentication components.
13 * @return {void} Nothing.
15 remoting.initIdentity = function() {
16 if (base.isAppsV2()) {
17 // TODO(jamiewalch): Add a getAuthDialog method to Application.Delegate
18 // to allow this behaviour to be customized.
20 new remoting.Identity(remoting.AuthDialog.getInstance());
22 // TODO(garykac) Remove this and replace with identity.
23 remoting.oauth2 = new remoting.OAuth2();
24 var oauth2 = /** @type {*} */ (remoting.oauth2);
25 remoting.identity = /** @type {remoting.Identity} */ (oauth2);
26 if (!remoting.identity.isAuthenticated()) {
27 remoting.AuthDialog.getInstance().show().then(function() {
28 remoting.oauth2.doAuthRedirect(function(){
29 window.location.reload();
37 * Removes the cached token and restarts the app.
39 * @return {void} Nothing.
41 remoting.handleAuthFailureAndRelaunch = function() {
42 remoting.identity.removeCachedAuthToken().then(function(){
43 if (base.isAppsV2()) {
44 base.Ipc.invoke('remoting.ActivationHandler.restart',
45 chrome.app.window.current().id);
47 window.location.reload();