-
Notifications
You must be signed in to change notification settings - Fork 0
/
myWebApp.html
83 lines (61 loc) · 2.02 KB
/
myWebApp.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Authenticate with an ArcGIS identity using ArcGIS Maps SDK for Javacript</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.26/"></script>
<style>
html,
body {
font-size: 150%;
margin: 10vh 10vw;
}
</style>
<script>
require([
"esri/portal/Portal",
"esri/identity/OAuthInfo",
"esri/identity/IdentityManager"
], function (Portal, OAuthInfo, esriId) {
const info = new OAuthInfo({
appId: "k0SjW4zW3RD2Brld",
portalUrl:"https://prdusertypes.maps.arcgis.com",
popup: false // the default
});
esriId.registerOAuthInfos([info]);
esriId
.checkSignInStatus(info.portalUrl + "/sharing")
.then(() => {
handleSignedIn();
})
.catch(() => {
handleSignedOut();
});
document.getElementById("sign-in").addEventListener("click", function () {
esriId.getCredential(info.portalUrl + "/sharing");
});
document.getElementById("sign-out").addEventListener("click", function () {
esriId.destroyCredentials();
window.location.reload();
});
function handleSignedIn() {
const portal = new Portal();
portal.load().then(() => {
const results = { name: portal.user.fullName, username: portal.user.username };
document.getElementById("results").innerText = JSON.stringify(results, null, 2);
});
}
function handleSignedOut() {
document.getElementById("results").innerText = 'Signed Out'
}
});
</script>
</head>
<body>
<button id="sign-in" class="btn btn-primary">Sign In</button>
<button id="sign-out" class="btn btn-primary">Sign Out</button>
<pre><code id="results"></code></pre>
</body>
</html>