unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.6k stars 693 forks source link

[WASM] `HttpClient` requests do not set `'credentials: include'` on `fetch` #5442

Open mikernet opened 3 years ago

mikernet commented 3 years ago

Current behavior

The underlying fetch call does not set credentials: 'include' so authentication cookies aren't sent for web service requests.

Expected behavior

Match HttpClient behavior in UWP and send authentication cookies or provide a mechanism to include credentials.

Workaround

Not sure - I searched and did not find any way to set the fetch request to include credentials in Uno.

Environment

Nuget Package:

Nuget Package Version(s): 3.5.0

Affected platform(s):

mikernet commented 3 years ago

It appears that adding this Blazor WASM package to the Uno WASM project and calling this method works:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.webassembly.http.webassemblyhttprequestmessageextensions.setbrowserrequestcredentials?view=aspnetcore-5.0

Should there be a different mechanism for Uno WASM to enable this or is this the approach that is recommended? It's a bit annoying to lose the ability to use all the HttpClient methods, instead only using ones that accept HttpRequestMessage and then having to call that extension method on every request message.

Either way, I think it would be good to document this somehow as finding this solution was rather difficult and I wasn't sure if it was going to work for Uno or if it was Blazor specific.