-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
46 lines (40 loc) · 1.4 KB
/
script.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
require([
'esri/portal/Portal',
'esri/identity/OAuthInfo',
'esri/identity/IdentityManager',
], (Portal, OAuthInfo, IdentityManager) => {
// UI elements
const loginButton = document.querySelector('#login-button');
const logoutButton = document.querySelector('#logout-button');
const greeting = document.querySelector('h1');
const info = new OAuthInfo({
appId: 'YOUR-REGISTERED-APP-ID-HERE',
popup: false,
//portalUrl: 'https://mywebsite.com/arcgis'
});
IdentityManager.registerOAuthInfos([info]);
loginButton.addEventListener('click', () =>
IdentityManager.getCredential(info.portalUrl + '/sharing')
);
logoutButton.addEventListener('click', () => {
IdentityManager.destroyCredentials();
window.location.reload();
});
const handleLoginSuccess = () => {
const portal = new Portal();
portal.authMode = 'immediate';
portal.load().then(() => {
console.log(portal);
// When the user is successfully logged in...
// ... hide the login button
loginButton.style = 'display: none';
// ... show the logout button
logoutButton.style = 'display: inline-block';
// ... greet the user by the user's name
greeting.textContent = `Welcome back, ${portal.user.fullName}!`;
});
};
IdentityManager.checkSignInStatus(info.portalUrl + '/sharing')
.then(handleLoginSuccess)
.catch(() => console.log('Not logged in'));
});