I'm using CreateLayer in my Add-In and passing an auth token to create a layer from a REST Map Server.
The issue I'm having is that after the token times out, the layers will no longer work and they have to create the layers again through a ribbon button I provided.
Is there a way to force the token to be generated after a timeout? Maybe I can receive an event in the add-in??? I just have no idea what to search for to make this happen.
Thanks in advance!
Use the SDK’s Authentication/Identity manager (AuthenticationManager / IdentityManager / ArcGISIdentityManager depending on product & API) and register credentials with it. The SDK will then attach credentials to requests and will call a registered challenge/callback when a token is rejected so your code can obtain a fresh token (or the SDK will handle refresh if you used an OAuth flow that issues refresh tokens). This is the usual, robust pattern.
var serviceUri = new Uri("https://myserver.example.com/arcgis/rest/services");
string token = await GetAccessTokenFromYourServerAsync(); // your token fetch
var expires = DateTimeOffset.UtcNow.AddMinutes(30); // use the expiry the token endpoint returned
// PregeneratedTokenCredential / AccessTokenCredential or similar depending on SDK
var credential = new PregeneratedTokenCredential(token, serviceUri, expires);
AuthenticationManager.Current.AddCredential(credential);