Select to view content in your preferred language

Adding a token to a FeatureLayer

241
1
02-29-2024 09:28 AM
JonathanHilgeman
New Contributor

I'm trying to migrate from 3.x to 4.x and I have a FeatureLayer that requires an auth token. I used to just pass it in the query string like "https://blahblah/MapServer/5?token=abc123" but in 4.x it seems to want the token to be passed in the HTTP header.

The documentation doesn't seem to cover this scenario. The docs simply tell me what header to pass, but since all the HTTP requests are handled by the SDK, I don't know how to configure those requests to have the header. I've tried using the IdentityManager's registerToken() call, and I don't get any errors but it doesn't use the token, either.

0 Kudos
1 Reply
JonathanHilgeman
New Contributor

So it turns out the IdentityManager.registerToken() approach DID work but the client application was using a couple of different subdomains. So I was trying:

server: "https://foo.example.com/arcgis/rest/services"

...but the the FeatureLayer was on bar.example.com, so the server parameter needed to be:

server: "https://bar.example.com/arcgis/rest/services"

Because of the mismatch, when I added the FeatureLayer, the IdentityManager couldn't find a token that was valid for that domain.

Once I used the correct subdomain, it worked.

0 Kudos