Pass a header paramter / value for each vector tiles request

1105
2
04-30-2024 04:26 AM
Labels (3)
jm2024
by
Emerging Contributor

Hi,

I am adding vector tiles support using your maps in MAUI app. What I can't pass through is that each request to our server requires additional header value with our token in order to get response.

For that I was using different map provider and I had interceptor service that was adding for each call from my BE endpoint header as:

request.Headers.Add(_tokenHeader, _token);

Now I was thinking about using

AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(ChallengeMethod);
but I am worried there's no option to setup it like that.

Can you suggest solution or it's not possible to inject header into request?

0 Kudos
2 Replies
dotMorten_esri
Esri Notable Contributor

You can use the ArcGISHttpClientHandler.HttpRequestBegin event to listen for and modify requests. 

ArcGISHttpClientHandler.HttpRequestBegin += (sender, message) =>
{
    if (message.RequestUri.Host == "www.myhost.com")
    {
        message.Headers.Add("MyTokenHeader", "MyToken");
    }
};

 

jm2024
by
Emerging Contributor

So that's what I did. Handler seems to trigger correct url.
This is still my result:

[0:] Accessing https://myurl.com requires authorization. Set a ChallengeHandler to provide credentials. For more information see https://developers.arcgis.com/net/security-and-authentication/
[0:] ArcGIS Maps SDK: Load Error: ServiceFeatureTable
System.Net.Http.HttpRequestException
Response status code does not indicate success: 401 (Unauthorized).
[0:] ArcGIS Maps SDK: Load Error: FeatureLayer
System.Net.Http.HttpRequestException
Response status code does not indicate success: 401 (Unauthorized).

 

0 Kudos