arcgis-maps-sdk-js-ai-context / arcgis-authentication
AGENTS.md0 starsChanged 7 months agoMITView on GitHub
Quick-reference decisions, checklists, and tables for authentication and authorization.
- Reads credentials
In this repository47 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/arcgis-ai-components/AGENTS.mdAGENTS.md
- skills/arcgis-charts/AGENTS.mdAGENTS.md
- skills/arcgis-coding-components/AGENTS.mdAGENTS.md
- skills/arcgis-core-maps/AGENTS.mdAGENTS.md
- skills/arcgis-editing/AGENTS.mdAGENTS.md
- skills/arcgis-embeddable-maps/AGENTS.mdAGENTS.md
- skills/arcgis-interaction/AGENTS.mdAGENTS.md
- skills/arcgis-layers/AGENTS.mdAGENTS.md
- skills/arcgis-starter-app/AGENTS.mdAGENTS.md
- skills/arcgis-visualization/AGENTS.mdAGENTS.md
- skills/arcgis-widgets-ui/AGENTS.mdAGENTS.md
- arcgis-3d-layersSkill
- arcgis-advanced-layersSkill
- arcgis-ai-componentsSkill
- arcgis-arcadeSkill
- arcgis-authenticationSkill
- arcgis-chartsSkill
- arcgis-cim-symbolsSkill
- arcgis-coding-componentsSkill
- arcgis-coordinates-projectionSkill
- arcgis-core-mapsSkill
- arcgis-core-utilitiesSkill
- arcgis-custom-renderingSkill
- arcgis-editingSkill
- arcgis-embeddable-mapsSkill
- arcgis-feature-effectsSkill
- arcgis-geometry-operationsSkill
- arcgis-imagerySkill
- arcgis-interactionSkill
- arcgis-knowledge-graphsSkill
- arcgis-layersSkill
- arcgis-map-toolsSkill
- arcgis-performanceSkill
- arcgis-popup-templatesSkill
- arcgis-portal-contentSkill
- arcgis-rest-servicesSkill
- arcgis-scene-environmentSkill
- arcgis-smart-mappingSkill
- arcgis-spatial-analysisSkill
- arcgis-starter-appSkill
- arcgis-tables-formsSkill
- arcgis-time-animationSkill
- arcgis-utility-networksSkill
- arcgis-visualizationSkill
- arcgis-widgets-advancedSkill
- arcgis-widgets-uiSkill
The file
Files
Agent Guide: arcgis-authentication
Quick-reference decisions, checklists, and tables for authentication and authorization.
API Key vs OAuth vs Identity Manager Decision Tree
- Does the app access only public basemaps, geocoding, or routing?
- Yes --> API Key (simplest)
- Does the app need to access the user's private content (web maps, feature services)?
- Yes --> OAuth 2.0 (user signs in)
- Is this a server-side app with no user interaction?
- Yes --> App token (client credentials OAuth flow, server-side only)
- Is the app connecting to ArcGIS Enterprise (on-premise)?
- Yes --> OAuth 2.0 with custom
portalUrl
- Yes --> OAuth 2.0 with custom
- Do you need to access multiple secured services and want automatic token management?
- Yes --> IdentityManager handles this automatically with OAuth or registered tokens
| Approach | User Sign-In | Setup Complexity | Use Case |
| API Key | No | Low | Public apps with basemaps/services |
| OAuth 2.0 (redirect) | Yes | Medium | Web apps needing user content |
| OAuth 2.0 (popup) | Yes | Medium | SPAs that stay on page |
<arcgis-oauth> component | Yes | Low | Quick OAuth with Map Components |
| Registered token | No | Low | Testing / known tokens |
OAuth Setup Checklist
Register your app
- Go to developers.arcgis.com (or your Enterprise portal)
- Create a new OAuth application
- Note the App ID (client ID)
- Add redirect URIs for your app (e.g.,
http://localhost:5173,https://yourapp.com) - For production: add referrer restrictions on the app registration
Implement in code
- Import
OAuthInfoandesriId(IdentityManager) - Create
OAuthInfo:new OAuthInfo({ appId: "YOUR_APP_ID" }) - Set
popup: falsefor redirect flow,popup: truefor popup window - Register:
esriId.registerOAuthInfos([oauthInfo]) - Check existing sign-in:
esriId.checkSignInStatus(portalUrl + "/sharing") - Trigger sign-in:
esriId.getCredential(portalUrl + "/sharing") - Load portal:
new Portal({ authMode: "immediate" })thenawait portal.load()
For Enterprise Portal
- Set
portalUrlon OAuthInfo:new OAuthInfo({ appId, portalUrl: "https://your-portal/portal" }) - Or set globally:
esriConfig.portalUrl = "https://your-portal/portal"
Using the OAuth Component
- Add
<arcgis-oauth app-id="YOUR_APP_ID">to HTML - Listen for
arcgisSignInandarcgisSignOutevents - Access credential from
event.detail.credential
Security Checklist
Token handling
- Never commit API keys or tokens to source control
- Use environment variables (e.g.,
VITE_ARCGIS_API_KEY) for API keys - For OAuth: tokens are managed by IdentityManager (no manual storage needed)
- Do not store tokens in
localStoragefor production apps
CORS and referrers
- Configure
esriConfig.request.trustedServersfor servers that should receive credentials - Set up proxy (
esriConfig.request.proxyUrl) for services that do not support CORS - Configure allowed referrers on your API key at developers.arcgis.com
- For Enterprise: ensure CORS is enabled on the portal and services
OAuth security
- Use HTTPS in production (OAuth redirects require it)
- Register only the redirect URIs you actually use
- Use
popup: false(redirect flow) when popup blockers are a concern - Handle token expiration: IdentityManager auto-refreshes, but test edge cases
API Key scoping
- Generate API keys with minimum required privileges (only basemaps, only geocoding, etc.)
- Set referrer restrictions to limit where the key can be used
- Use separate keys for development and production
- Rotate keys periodically
Sign-In / Sign-Out Flow Summary
App loads
--> checkSignInStatus()
--> Signed in? Load Portal, display user info
--> Not signed in? Show sign-in button
--> User clicks sign-in
--> getCredential() triggers OAuth redirect/popup
--> User authenticates at ArcGIS
--> Redirect back with token
--> Load Portal, display user info
Sign out:
--> esriId.destroyCredentials()
--> window.location.reload()Common Token Errors
| Error | Likely Cause | Fix |
identity-manager:not-authorized | Missing or expired token | Trigger re-authentication |
403 Forbidden | API key lacks required privilege | Add privilege at developers.arcgis.com |
498 Invalid Token | Token expired or revoked | Refresh or re-authenticate |
499 Token Required | Secured service, no token provided | Register OAuthInfo or set API key |
| CORS error on token request | Portal not configured for CORS | Add to trustedServers or use proxy |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

