Authentication in Browser-based Apps
In the Node.js guide we explained how to instantiate an ApplicationSession
with hardcoded credentials. In the browser, you need to use OAuth 2.0 and have users sign directly into ArcGIS Online or ArcGIS Enterprise.
Resources
// register your own app to create a unique clientId
const clientId = "abc123";
UserSession.beginOAuth2({
clientId,
redirectUri: "https://yourapp.com/authenticate.html",
}).then(session);
After the user has logged in, the session
will keep track of individual federatedServers
that are known to be federated and pass a token through when making requests.
request(url, { authentication: session });