blazor.net with HttpClient sending credenials


blazor.net with HttpClient sending credenials



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


Blazor.Net


HttpClient



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.


httpClient


PlatformNotSupported



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


HttpClient


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#.


XMLHttpRequest


withCredentials


true



Thanks,




2 Answers
2



I believe your solution should resides in this class:
Microsoft.AspNetCore.Blazor.Browser.Http.BrowserHttpMessageHandler



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.





Thanks I didn't consider extension methods and did not know about the Handler. I will try them.
– user600554
Jul 2 at 12:14






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy