-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth_init.js
59 lines (52 loc) · 1.71 KB
/
auth_init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* Get the user's email address and full name.
*
* @param {function(string,string):void} onUserInfoAvailable Callback invoked
* when the user's email address and full name are available.
* @return {void} Nothing.
*/
remoting.initIdentity = function(onUserInfoAvailable) {
/** @param {remoting.Error} error */
function onGetIdentityInfoError(error) {
remoting.showErrorMessage(error);
}
if (base.isAppsV2()) {
remoting.identity =
new remoting.Identity(remoting.AuthDialog.getInstance());
} else {
// TODO(garykac) Remove this and replace with identity.
remoting.oauth2 = new remoting.OAuth2();
var oauth2 = /** @type {*} */ (remoting.oauth2);
remoting.identity = /** @type {remoting.Identity} */ (oauth2);
if (!remoting.identity.isAuthenticated()) {
remoting.AuthDialog.getInstance().show().then(function() {
remoting.oauth2.doAuthRedirect(function(){
window.location.reload();
});
});
}
}
remoting.identity.getUserInfo(onUserInfoAvailable,
onGetIdentityInfoError);
};
/**
* Removes the cached token and restarts the app.
*
* @return {void} Nothing.
*/
remoting.handleAuthFailureAndRelaunch = function() {
remoting.identity.removeCachedAuthToken(function(){
if (base.isAppsV2()) {
base.Ipc.invoke('remoting.ActivationHandler.restart',
chrome.app.window.current().id);
} else {
window.location.reload();
}
});
};