@saschabrunnerch/arcgis-maps-sdk-js-ai-context 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -203
- package/bin/cli.js +157 -173
- package/contexts/4.34/{claude → skills}/arcgis-3d-advanced/SKILL.md +586 -586
- package/contexts/4.34/{claude → skills}/arcgis-advanced-layers/SKILL.md +431 -431
- package/contexts/4.34/{claude → skills}/arcgis-analysis-services/SKILL.md +607 -607
- package/contexts/4.34/{claude → skills}/arcgis-authentication/SKILL.md +301 -301
- package/contexts/4.34/{claude → skills}/arcgis-cim-symbols/SKILL.md +486 -486
- package/contexts/4.34/{claude → skills}/arcgis-coordinates-projection/SKILL.md +406 -406
- package/contexts/4.34/{claude → skills}/arcgis-core-maps/SKILL.md +739 -739
- package/contexts/4.34/{claude → skills}/arcgis-core-utilities/SKILL.md +732 -732
- package/contexts/4.34/{claude → skills}/arcgis-custom-rendering/SKILL.md +445 -445
- package/contexts/4.34/{claude → skills}/arcgis-editing-advanced/SKILL.md +702 -702
- package/contexts/4.34/{claude → skills}/arcgis-feature-effects/SKILL.md +393 -393
- package/contexts/4.34/{claude → skills}/arcgis-geometry-operations/SKILL.md +489 -489
- package/contexts/4.34/{claude → skills}/arcgis-imagery/SKILL.md +307 -307
- package/contexts/4.34/{claude → skills}/arcgis-interaction/SKILL.md +572 -572
- package/contexts/4.34/{claude → skills}/arcgis-knowledge-graphs/SKILL.md +582 -582
- package/contexts/4.34/{claude → skills}/arcgis-layers/SKILL.md +601 -601
- package/contexts/4.34/{claude → skills}/arcgis-map-tools/SKILL.md +668 -668
- package/contexts/4.34/{claude → skills}/arcgis-media-layers/SKILL.md +290 -290
- package/contexts/4.34/{claude → skills}/arcgis-portal-content/SKILL.md +679 -679
- package/contexts/4.34/{claude → skills}/arcgis-scene-effects/SKILL.md +512 -512
- package/contexts/4.34/{claude → skills}/arcgis-smart-mapping/SKILL.md +686 -686
- package/contexts/4.34/{claude → skills}/arcgis-starter-app-extended/SKILL.md +649 -649
- package/contexts/4.34/{claude → skills}/arcgis-tables-forms/SKILL.md +877 -877
- package/contexts/4.34/{claude → skills}/arcgis-time-animation/SKILL.md +722 -722
- package/contexts/4.34/{claude → skills}/arcgis-utility-networks/SKILL.md +301 -301
- package/contexts/4.34/{claude → skills}/arcgis-visualization/SKILL.md +580 -580
- package/contexts/4.34/{claude → skills}/arcgis-widgets-ui/SKILL.md +574 -574
- package/lib/installer.js +19 -104
- package/package.json +45 -45
- package/contexts/4.34/copilot/arcgis-3d.instructions.md +0 -267
- package/contexts/4.34/copilot/arcgis-analysis.instructions.md +0 -294
- package/contexts/4.34/copilot/arcgis-arcade.instructions.md +0 -234
- package/contexts/4.34/copilot/arcgis-authentication.instructions.md +0 -187
- package/contexts/4.34/copilot/arcgis-cim-symbols.instructions.md +0 -177
- package/contexts/4.34/copilot/arcgis-core-maps.instructions.md +0 -246
- package/contexts/4.34/copilot/arcgis-core-utilities.instructions.md +0 -247
- package/contexts/4.34/copilot/arcgis-editing.instructions.md +0 -262
- package/contexts/4.34/copilot/arcgis-geometry.instructions.md +0 -225
- package/contexts/4.34/copilot/arcgis-layers.instructions.md +0 -278
- package/contexts/4.34/copilot/arcgis-popup-templates.instructions.md +0 -266
- package/contexts/4.34/copilot/arcgis-portal-advanced.instructions.md +0 -275
- package/contexts/4.34/copilot/arcgis-smart-mapping.instructions.md +0 -184
- package/contexts/4.34/copilot/arcgis-starter-app-extended.instructions.md +0 -643
- package/contexts/4.34/copilot/arcgis-starter-app.instructions.md +0 -268
- package/contexts/4.34/copilot/arcgis-time-animation.instructions.md +0 -112
- package/contexts/4.34/copilot/arcgis-visualization.instructions.md +0 -321
- package/contexts/4.34/copilot/arcgis-widgets-ui.instructions.md +0 -277
- /package/contexts/4.34/{claude → skills}/arcgis-arcade/SKILL.md +0 -0
- /package/contexts/4.34/{claude → skills}/arcgis-popup-templates/SKILL.md +0 -0
- /package/contexts/4.34/{claude → skills}/arcgis-starter-app/SKILL.md +0 -0
|
@@ -1,301 +1,301 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: arcgis-authentication
|
|
3
|
-
description: Implement authentication with ArcGIS using OAuth 2.0, API keys, and identity management. Use for accessing secured services, portal items, and user-specific content.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# ArcGIS Authentication
|
|
7
|
-
|
|
8
|
-
Use this skill for implementing authentication, OAuth, API keys, and identity management.
|
|
9
|
-
|
|
10
|
-
## OAuth 2.0 Authentication
|
|
11
|
-
|
|
12
|
-
### Basic OAuth Setup
|
|
13
|
-
```javascript
|
|
14
|
-
import OAuthInfo from "@arcgis/core/identity/OAuthInfo.js";
|
|
15
|
-
import esriId from "@arcgis/core/identity/IdentityManager.js";
|
|
16
|
-
import Portal from "@arcgis/core/portal/Portal.js";
|
|
17
|
-
|
|
18
|
-
// Create OAuthInfo with your app ID
|
|
19
|
-
const oauthInfo = new OAuthInfo({
|
|
20
|
-
appId: "YOUR_APP_ID", // Register at developers.arcgis.com
|
|
21
|
-
popup: false // false = redirect, true = popup window
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Register with IdentityManager
|
|
25
|
-
esriId.registerOAuthInfos([oauthInfo]);
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Check Sign-In Status
|
|
29
|
-
```javascript
|
|
30
|
-
async function checkSignIn() {
|
|
31
|
-
try {
|
|
32
|
-
await esriId.checkSignInStatus(oauthInfo.portalUrl + "/sharing");
|
|
33
|
-
// User is signed in
|
|
34
|
-
const portal = new Portal({ authMode: "immediate" });
|
|
35
|
-
await portal.load();
|
|
36
|
-
console.log("Signed in as:", portal.user.username);
|
|
37
|
-
return portal;
|
|
38
|
-
} catch {
|
|
39
|
-
// User is not signed in
|
|
40
|
-
console.log("Not signed in");
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Sign In
|
|
47
|
-
```javascript
|
|
48
|
-
async function signIn() {
|
|
49
|
-
try {
|
|
50
|
-
const credential = await esriId.getCredential(
|
|
51
|
-
oauthInfo.portalUrl + "/sharing"
|
|
52
|
-
);
|
|
53
|
-
console.log("Credential obtained:", credential);
|
|
54
|
-
return credential;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Sign in failed:", error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Sign Out
|
|
62
|
-
```javascript
|
|
63
|
-
function signOut() {
|
|
64
|
-
esriId.destroyCredentials();
|
|
65
|
-
window.location.reload();
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Complete OAuth Flow
|
|
70
|
-
```javascript
|
|
71
|
-
import OAuthInfo from "@arcgis/core/identity/OAuthInfo.js";
|
|
72
|
-
import esriId from "@arcgis/core/identity/IdentityManager.js";
|
|
73
|
-
import Portal from "@arcgis/core/portal/Portal.js";
|
|
74
|
-
|
|
75
|
-
const oauthInfo = new OAuthInfo({
|
|
76
|
-
appId: "YOUR_APP_ID"
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
esriId.registerOAuthInfos([oauthInfo]);
|
|
80
|
-
|
|
81
|
-
// Check if already signed in
|
|
82
|
-
esriId.checkSignInStatus(oauthInfo.portalUrl + "/sharing")
|
|
83
|
-
.then(() => {
|
|
84
|
-
// Already signed in, load portal
|
|
85
|
-
const portal = new Portal({ authMode: "immediate" });
|
|
86
|
-
return portal.load();
|
|
87
|
-
})
|
|
88
|
-
.then((portal) => {
|
|
89
|
-
console.log("Welcome,", portal.user.fullName);
|
|
90
|
-
displayUserContent(portal);
|
|
91
|
-
})
|
|
92
|
-
.catch(() => {
|
|
93
|
-
// Not signed in, show sign-in button
|
|
94
|
-
showSignInButton();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
function showSignInButton() {
|
|
98
|
-
const btn = document.getElementById("signInBtn");
|
|
99
|
-
btn.onclick = () => {
|
|
100
|
-
esriId.getCredential(oauthInfo.portalUrl + "/sharing")
|
|
101
|
-
.then(() => {
|
|
102
|
-
window.location.reload();
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## OAuth Component
|
|
109
|
-
|
|
110
|
-
```html
|
|
111
|
-
<!-- Using OAuth component -->
|
|
112
|
-
<arcgis-oauth app-id="YOUR_APP_ID"></arcgis-oauth>
|
|
113
|
-
|
|
114
|
-
<script type="module">
|
|
115
|
-
const oauthComponent = document.querySelector("arcgis-oauth");
|
|
116
|
-
|
|
117
|
-
oauthComponent.addEventListener("arcgisSignIn", (event) => {
|
|
118
|
-
console.log("Signed in:", event.detail.credential);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
oauthComponent.addEventListener("arcgisSignOut", () => {
|
|
122
|
-
console.log("Signed out");
|
|
123
|
-
});
|
|
124
|
-
</script>
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## API Keys
|
|
128
|
-
|
|
129
|
-
### Configure API Key
|
|
130
|
-
```javascript
|
|
131
|
-
import esriConfig from "@arcgis/core/config.js";
|
|
132
|
-
|
|
133
|
-
// Set API key for accessing services
|
|
134
|
-
esriConfig.apiKey = "YOUR_API_KEY";
|
|
135
|
-
|
|
136
|
-
// Now basemaps and services will use the API key
|
|
137
|
-
const map = new Map({
|
|
138
|
-
basemap: "arcgis/streets" // Requires API key
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### API Key in HTML
|
|
143
|
-
```html
|
|
144
|
-
<script>
|
|
145
|
-
// Set before loading the SDK
|
|
146
|
-
window.esriConfig = {
|
|
147
|
-
apiKey: "YOUR_API_KEY"
|
|
148
|
-
};
|
|
149
|
-
</script>
|
|
150
|
-
<script src="https://js.arcgis.com/4.34/"></script>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Enterprise Portal Authentication
|
|
154
|
-
|
|
155
|
-
### Configure for Enterprise Portal
|
|
156
|
-
```javascript
|
|
157
|
-
const oauthInfo = new OAuthInfo({
|
|
158
|
-
appId: "YOUR_APP_ID",
|
|
159
|
-
portalUrl: "https://your-portal.com/portal",
|
|
160
|
-
popup: true
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
esriId.registerOAuthInfos([oauthInfo]);
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### Set Portal URL Globally
|
|
167
|
-
```javascript
|
|
168
|
-
import esriConfig from "@arcgis/core/config.js";
|
|
169
|
-
|
|
170
|
-
esriConfig.portalUrl = "https://your-portal.com/portal";
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Token-Based Authentication
|
|
174
|
-
|
|
175
|
-
### Get Token Manually
|
|
176
|
-
```javascript
|
|
177
|
-
const credential = await esriId.getCredential("https://services.arcgis.com/...");
|
|
178
|
-
console.log("Token:", credential.token);
|
|
179
|
-
console.log("Expires:", new Date(credential.expires));
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Register Token
|
|
183
|
-
```javascript
|
|
184
|
-
esriId.registerToken({
|
|
185
|
-
server: "https://services.arcgis.com/",
|
|
186
|
-
token: "YOUR_TOKEN"
|
|
187
|
-
});
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Portal User Information
|
|
191
|
-
|
|
192
|
-
```javascript
|
|
193
|
-
import Portal from "@arcgis/core/portal/Portal.js";
|
|
194
|
-
|
|
195
|
-
const portal = new Portal({ authMode: "immediate" });
|
|
196
|
-
await portal.load();
|
|
197
|
-
|
|
198
|
-
// User info
|
|
199
|
-
console.log("Username:", portal.user.username);
|
|
200
|
-
console.log("Full name:", portal.user.fullName);
|
|
201
|
-
console.log("Email:", portal.user.email);
|
|
202
|
-
console.log("Role:", portal.user.role);
|
|
203
|
-
console.log("Thumbnail:", portal.user.thumbnailUrl);
|
|
204
|
-
|
|
205
|
-
// Organization info
|
|
206
|
-
console.log("Org name:", portal.name);
|
|
207
|
-
console.log("Org ID:", portal.id);
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Query User Items
|
|
211
|
-
|
|
212
|
-
```javascript
|
|
213
|
-
import Portal from "@arcgis/core/portal/Portal.js";
|
|
214
|
-
import PortalQueryParams from "@arcgis/core/portal/PortalQueryParams.js";
|
|
215
|
-
|
|
216
|
-
const portal = new Portal({ authMode: "immediate" });
|
|
217
|
-
await portal.load();
|
|
218
|
-
|
|
219
|
-
// Query user's items
|
|
220
|
-
const queryParams = new PortalQueryParams({
|
|
221
|
-
query: `owner:${portal.user.username}`,
|
|
222
|
-
sortField: "modified",
|
|
223
|
-
sortOrder: "desc",
|
|
224
|
-
num: 20
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
const result = await portal.queryItems(queryParams);
|
|
228
|
-
|
|
229
|
-
result.results.forEach(item => {
|
|
230
|
-
console.log(item.title, item.type, item.id);
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Credential Persistence
|
|
235
|
-
|
|
236
|
-
```javascript
|
|
237
|
-
// Credentials are stored in localStorage by default
|
|
238
|
-
// Disable persistence
|
|
239
|
-
esriId.useSignInPage = false;
|
|
240
|
-
|
|
241
|
-
// Clear stored credentials
|
|
242
|
-
esriId.destroyCredentials();
|
|
243
|
-
|
|
244
|
-
// Check for stored credentials on load
|
|
245
|
-
const credentials = esriId.credentials;
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## Handling Authentication Errors
|
|
249
|
-
|
|
250
|
-
```javascript
|
|
251
|
-
// Global handler for authentication challenges
|
|
252
|
-
esriId.on("credential-create", (event) => {
|
|
253
|
-
console.log("New credential created:", event.credential);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// Handle layer authentication errors
|
|
257
|
-
layer.on("layerview-create-error", (event) => {
|
|
258
|
-
if (event.error.name === "identity-manager:not-authorized") {
|
|
259
|
-
console.log("Authentication required for this layer");
|
|
260
|
-
signIn();
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
## Trusted Servers
|
|
266
|
-
|
|
267
|
-
```javascript
|
|
268
|
-
import esriConfig from "@arcgis/core/config.js";
|
|
269
|
-
|
|
270
|
-
// Add servers that should receive credentials automatically
|
|
271
|
-
esriConfig.request.trustedServers.push("https://services.arcgis.com");
|
|
272
|
-
esriConfig.request.trustedServers.push("https://your-server.com");
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
## CORS and Proxy
|
|
276
|
-
|
|
277
|
-
```javascript
|
|
278
|
-
import esriConfig from "@arcgis/core/config.js";
|
|
279
|
-
|
|
280
|
-
// Configure proxy for cross-origin requests
|
|
281
|
-
esriConfig.request.proxyUrl = "/proxy/";
|
|
282
|
-
|
|
283
|
-
// Configure proxy rules
|
|
284
|
-
esriConfig.request.proxyRules.push({
|
|
285
|
-
urlPrefix: "https://services.arcgis.com",
|
|
286
|
-
proxyUrl: "/proxy/"
|
|
287
|
-
});
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## Common Pitfalls
|
|
291
|
-
|
|
292
|
-
1. **App ID registration**: App ID must be registered with correct redirect URIs
|
|
293
|
-
|
|
294
|
-
2. **Popup blockers**: OAuth popups may be blocked - use redirect flow as fallback
|
|
295
|
-
|
|
296
|
-
3. **Token expiration**: Tokens expire - handle refresh or re-authentication
|
|
297
|
-
|
|
298
|
-
4. **CORS errors**: Configure trusted servers or use proxy for cross-origin
|
|
299
|
-
|
|
300
|
-
5. **Portal URL mismatch**: Ensure portal URL matches exactly (trailing slashes matter)
|
|
301
|
-
|
|
1
|
+
---
|
|
2
|
+
name: arcgis-authentication
|
|
3
|
+
description: Implement authentication with ArcGIS using OAuth 2.0, API keys, and identity management. Use for accessing secured services, portal items, and user-specific content.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ArcGIS Authentication
|
|
7
|
+
|
|
8
|
+
Use this skill for implementing authentication, OAuth, API keys, and identity management.
|
|
9
|
+
|
|
10
|
+
## OAuth 2.0 Authentication
|
|
11
|
+
|
|
12
|
+
### Basic OAuth Setup
|
|
13
|
+
```javascript
|
|
14
|
+
import OAuthInfo from "@arcgis/core/identity/OAuthInfo.js";
|
|
15
|
+
import esriId from "@arcgis/core/identity/IdentityManager.js";
|
|
16
|
+
import Portal from "@arcgis/core/portal/Portal.js";
|
|
17
|
+
|
|
18
|
+
// Create OAuthInfo with your app ID
|
|
19
|
+
const oauthInfo = new OAuthInfo({
|
|
20
|
+
appId: "YOUR_APP_ID", // Register at developers.arcgis.com
|
|
21
|
+
popup: false // false = redirect, true = popup window
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Register with IdentityManager
|
|
25
|
+
esriId.registerOAuthInfos([oauthInfo]);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Check Sign-In Status
|
|
29
|
+
```javascript
|
|
30
|
+
async function checkSignIn() {
|
|
31
|
+
try {
|
|
32
|
+
await esriId.checkSignInStatus(oauthInfo.portalUrl + "/sharing");
|
|
33
|
+
// User is signed in
|
|
34
|
+
const portal = new Portal({ authMode: "immediate" });
|
|
35
|
+
await portal.load();
|
|
36
|
+
console.log("Signed in as:", portal.user.username);
|
|
37
|
+
return portal;
|
|
38
|
+
} catch {
|
|
39
|
+
// User is not signed in
|
|
40
|
+
console.log("Not signed in");
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Sign In
|
|
47
|
+
```javascript
|
|
48
|
+
async function signIn() {
|
|
49
|
+
try {
|
|
50
|
+
const credential = await esriId.getCredential(
|
|
51
|
+
oauthInfo.portalUrl + "/sharing"
|
|
52
|
+
);
|
|
53
|
+
console.log("Credential obtained:", credential);
|
|
54
|
+
return credential;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("Sign in failed:", error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Sign Out
|
|
62
|
+
```javascript
|
|
63
|
+
function signOut() {
|
|
64
|
+
esriId.destroyCredentials();
|
|
65
|
+
window.location.reload();
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Complete OAuth Flow
|
|
70
|
+
```javascript
|
|
71
|
+
import OAuthInfo from "@arcgis/core/identity/OAuthInfo.js";
|
|
72
|
+
import esriId from "@arcgis/core/identity/IdentityManager.js";
|
|
73
|
+
import Portal from "@arcgis/core/portal/Portal.js";
|
|
74
|
+
|
|
75
|
+
const oauthInfo = new OAuthInfo({
|
|
76
|
+
appId: "YOUR_APP_ID"
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
esriId.registerOAuthInfos([oauthInfo]);
|
|
80
|
+
|
|
81
|
+
// Check if already signed in
|
|
82
|
+
esriId.checkSignInStatus(oauthInfo.portalUrl + "/sharing")
|
|
83
|
+
.then(() => {
|
|
84
|
+
// Already signed in, load portal
|
|
85
|
+
const portal = new Portal({ authMode: "immediate" });
|
|
86
|
+
return portal.load();
|
|
87
|
+
})
|
|
88
|
+
.then((portal) => {
|
|
89
|
+
console.log("Welcome,", portal.user.fullName);
|
|
90
|
+
displayUserContent(portal);
|
|
91
|
+
})
|
|
92
|
+
.catch(() => {
|
|
93
|
+
// Not signed in, show sign-in button
|
|
94
|
+
showSignInButton();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
function showSignInButton() {
|
|
98
|
+
const btn = document.getElementById("signInBtn");
|
|
99
|
+
btn.onclick = () => {
|
|
100
|
+
esriId.getCredential(oauthInfo.portalUrl + "/sharing")
|
|
101
|
+
.then(() => {
|
|
102
|
+
window.location.reload();
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## OAuth Component
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<!-- Using OAuth component -->
|
|
112
|
+
<arcgis-oauth app-id="YOUR_APP_ID"></arcgis-oauth>
|
|
113
|
+
|
|
114
|
+
<script type="module">
|
|
115
|
+
const oauthComponent = document.querySelector("arcgis-oauth");
|
|
116
|
+
|
|
117
|
+
oauthComponent.addEventListener("arcgisSignIn", (event) => {
|
|
118
|
+
console.log("Signed in:", event.detail.credential);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
oauthComponent.addEventListener("arcgisSignOut", () => {
|
|
122
|
+
console.log("Signed out");
|
|
123
|
+
});
|
|
124
|
+
</script>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API Keys
|
|
128
|
+
|
|
129
|
+
### Configure API Key
|
|
130
|
+
```javascript
|
|
131
|
+
import esriConfig from "@arcgis/core/config.js";
|
|
132
|
+
|
|
133
|
+
// Set API key for accessing services
|
|
134
|
+
esriConfig.apiKey = "YOUR_API_KEY";
|
|
135
|
+
|
|
136
|
+
// Now basemaps and services will use the API key
|
|
137
|
+
const map = new Map({
|
|
138
|
+
basemap: "arcgis/streets" // Requires API key
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### API Key in HTML
|
|
143
|
+
```html
|
|
144
|
+
<script>
|
|
145
|
+
// Set before loading the SDK
|
|
146
|
+
window.esriConfig = {
|
|
147
|
+
apiKey: "YOUR_API_KEY"
|
|
148
|
+
};
|
|
149
|
+
</script>
|
|
150
|
+
<script src="https://js.arcgis.com/4.34/"></script>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Enterprise Portal Authentication
|
|
154
|
+
|
|
155
|
+
### Configure for Enterprise Portal
|
|
156
|
+
```javascript
|
|
157
|
+
const oauthInfo = new OAuthInfo({
|
|
158
|
+
appId: "YOUR_APP_ID",
|
|
159
|
+
portalUrl: "https://your-portal.com/portal",
|
|
160
|
+
popup: true
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
esriId.registerOAuthInfos([oauthInfo]);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Set Portal URL Globally
|
|
167
|
+
```javascript
|
|
168
|
+
import esriConfig from "@arcgis/core/config.js";
|
|
169
|
+
|
|
170
|
+
esriConfig.portalUrl = "https://your-portal.com/portal";
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Token-Based Authentication
|
|
174
|
+
|
|
175
|
+
### Get Token Manually
|
|
176
|
+
```javascript
|
|
177
|
+
const credential = await esriId.getCredential("https://services.arcgis.com/...");
|
|
178
|
+
console.log("Token:", credential.token);
|
|
179
|
+
console.log("Expires:", new Date(credential.expires));
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Register Token
|
|
183
|
+
```javascript
|
|
184
|
+
esriId.registerToken({
|
|
185
|
+
server: "https://services.arcgis.com/",
|
|
186
|
+
token: "YOUR_TOKEN"
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Portal User Information
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
import Portal from "@arcgis/core/portal/Portal.js";
|
|
194
|
+
|
|
195
|
+
const portal = new Portal({ authMode: "immediate" });
|
|
196
|
+
await portal.load();
|
|
197
|
+
|
|
198
|
+
// User info
|
|
199
|
+
console.log("Username:", portal.user.username);
|
|
200
|
+
console.log("Full name:", portal.user.fullName);
|
|
201
|
+
console.log("Email:", portal.user.email);
|
|
202
|
+
console.log("Role:", portal.user.role);
|
|
203
|
+
console.log("Thumbnail:", portal.user.thumbnailUrl);
|
|
204
|
+
|
|
205
|
+
// Organization info
|
|
206
|
+
console.log("Org name:", portal.name);
|
|
207
|
+
console.log("Org ID:", portal.id);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Query User Items
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
import Portal from "@arcgis/core/portal/Portal.js";
|
|
214
|
+
import PortalQueryParams from "@arcgis/core/portal/PortalQueryParams.js";
|
|
215
|
+
|
|
216
|
+
const portal = new Portal({ authMode: "immediate" });
|
|
217
|
+
await portal.load();
|
|
218
|
+
|
|
219
|
+
// Query user's items
|
|
220
|
+
const queryParams = new PortalQueryParams({
|
|
221
|
+
query: `owner:${portal.user.username}`,
|
|
222
|
+
sortField: "modified",
|
|
223
|
+
sortOrder: "desc",
|
|
224
|
+
num: 20
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const result = await portal.queryItems(queryParams);
|
|
228
|
+
|
|
229
|
+
result.results.forEach(item => {
|
|
230
|
+
console.log(item.title, item.type, item.id);
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Credential Persistence
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
// Credentials are stored in localStorage by default
|
|
238
|
+
// Disable persistence
|
|
239
|
+
esriId.useSignInPage = false;
|
|
240
|
+
|
|
241
|
+
// Clear stored credentials
|
|
242
|
+
esriId.destroyCredentials();
|
|
243
|
+
|
|
244
|
+
// Check for stored credentials on load
|
|
245
|
+
const credentials = esriId.credentials;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Handling Authentication Errors
|
|
249
|
+
|
|
250
|
+
```javascript
|
|
251
|
+
// Global handler for authentication challenges
|
|
252
|
+
esriId.on("credential-create", (event) => {
|
|
253
|
+
console.log("New credential created:", event.credential);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Handle layer authentication errors
|
|
257
|
+
layer.on("layerview-create-error", (event) => {
|
|
258
|
+
if (event.error.name === "identity-manager:not-authorized") {
|
|
259
|
+
console.log("Authentication required for this layer");
|
|
260
|
+
signIn();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Trusted Servers
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
import esriConfig from "@arcgis/core/config.js";
|
|
269
|
+
|
|
270
|
+
// Add servers that should receive credentials automatically
|
|
271
|
+
esriConfig.request.trustedServers.push("https://services.arcgis.com");
|
|
272
|
+
esriConfig.request.trustedServers.push("https://your-server.com");
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## CORS and Proxy
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
import esriConfig from "@arcgis/core/config.js";
|
|
279
|
+
|
|
280
|
+
// Configure proxy for cross-origin requests
|
|
281
|
+
esriConfig.request.proxyUrl = "/proxy/";
|
|
282
|
+
|
|
283
|
+
// Configure proxy rules
|
|
284
|
+
esriConfig.request.proxyRules.push({
|
|
285
|
+
urlPrefix: "https://services.arcgis.com",
|
|
286
|
+
proxyUrl: "/proxy/"
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Common Pitfalls
|
|
291
|
+
|
|
292
|
+
1. **App ID registration**: App ID must be registered with correct redirect URIs
|
|
293
|
+
|
|
294
|
+
2. **Popup blockers**: OAuth popups may be blocked - use redirect flow as fallback
|
|
295
|
+
|
|
296
|
+
3. **Token expiration**: Tokens expire - handle refresh or re-authentication
|
|
297
|
+
|
|
298
|
+
4. **CORS errors**: Configure trusted servers or use proxy for cross-origin
|
|
299
|
+
|
|
300
|
+
5. **Portal URL mismatch**: Ensure portal URL matches exactly (trailing slashes matter)
|
|
301
|
+
|