It works unstable, sometimes it authenticates successfully, sometimes it fails.
Log error:
Unhandled Exception: ArcGISException: code=18004; A token or API key is required.; A token or API key was not provided to access https://arcgis.xyz.vn/arcgis/rest/services/xyz/MapServer/
Solved! Go to Solution.
Actually re-reviewing your code, with the PregeneratedTokenCredential, this is slightly different to the TokenCredential workflow. Are you looking to have a user login experience in your app? If so, you can either use the TokenCredential or OAuthUserCredential workflows. For these you need to override the handleArcGISAuthenticationChallenge method.
If you are looking to use a pregenerated token, then this is for the workflow where you are using a token generated outside of your application. i.e. you can just get your pregenerated token and add this to the credential store - you just need to make sure you do this before you load the map or any secured services you are using.
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.add(credential: pregeneratedTokenCredential);
Hi @locho - thanks for sending your question through the forum 🙂
Hmm I wonder if this could be a timing issue if it's working sometimes and not others. May I ask what is it you are trying to load - a Portal, a type of layer, something else? And are you explicitly calling and awaiting load on whatever it is you are loading? Do you have any repro code from that part of the app?
Thanks - any other info you can provide may assist us in helping figure things out!
I have loaded ArcGIS MapImageLayer just like the sample code
https://developers.arcgis.com/flutter/sample-code/add-map-image-layer/
Thanks.
Actually re-reviewing your code, with the PregeneratedTokenCredential, this is slightly different to the TokenCredential workflow. Are you looking to have a user login experience in your app? If so, you can either use the TokenCredential or OAuthUserCredential workflows. For these you need to override the handleArcGISAuthenticationChallenge method.
If you are looking to use a pregenerated token, then this is for the workflow where you are using a token generated outside of your application. i.e. you can just get your pregenerated token and add this to the credential store - you just need to make sure you do this before you load the map or any secured services you are using.
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.add(credential: pregeneratedTokenCredential);