blazor.net with HttpClient sending credentials

blazor dotnet-httpclient

Question

I have an api hosted on IIS that I am trying to call through a Blazor.Net client app with the HttpClient as provided in the example.

Since the api endpoint is hosted on IIS with windows authentication, I need to include credentials when the call is made.

I tried to create an instance of the httpClient instead of using the static method provided in the examples but I receive the PlatformNotSupported exception.

Is there a way to pass credentials with the Static HttpClient as used in Blazor.net?

If I use JavaScript interop with XMLHttpRequest and set withCredentials to true, the api returns data. However I would rather not use js to get the data but rather C#.

Thanks,

Popular Answer

Normally the browser should take care of this, that's why you need a browser that is Windows Authentication compatible. See here for an explanation of how Windows Authentication interacts with the browser.

So if that does not work by default, I guess Blazor/Mono does not supports this yet. But you are able to include your own authorization headers in the http call in blazor. I have an example here how to do that (for a jwt token). So if you are able to somehow get the Windows token from somewhere you could try that.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow