Aspnetcore.docs: credentials = FetchCredentialsOption.Include doesn't work on client-side

Created on 6 Nov 2019  Â·  9Comments  Â·  Source: dotnet/AspNetCore.Docs

If you try the sample with

requestMessage.Properties[WebAssemblyHttpMessageHandler.FetchArgs] = new
{ 
    credentials = FetchCredentialsOption.Include
};

The exception

> WASM: System.Net.Http.HttpRequestException: TypeError: Failed to execute 'fetch' on 'Window': The provided value '2' is not a valid enum value of type RequestCredentials.

Is logged in the console

The workarroud is to use

requestMessage.Properties[WebAssemblyHttpMessageHandler.FetchArgs] = new
{ 
    credentials = "include"
};

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Blazor P0 Source - Docs.ms doc-bug

Most helpful comment

@kjpou1 As far as I can tell, the current version of Mono doesn't provide any per-request way to set a credentials option. The credentials option is always set to the value of the globally static DefaultCredentials property: https://github.com/mono/mono/blob/5d981c267981505f425826ae0a3cc79dd08ecde4/sdks/wasm/framework/src/WebAssembly.Net.Http/WasmHttpMessageHandler.cs#L76. Do you think at some point it will be possible to reintroduce support for setting the credentials option on a per-request basis?

@aguacongas I'm afraid the docs you're pointing to are out of date, as is the code sample you've posted. You're referring to a type WebAssemblyHttpMessageHandler that doesn't exist in current versions of Blazor (or the underlying Mono WebAssembly runtime). It doesn't look to me like your workaround would work with the current framework. Or if I'm missing something about where this type is defined, please let me know!

@guardrex Could we remove the section of the docs that talks about FetchCredentialsOption being put into a Properties dictionary? Currently the only thing in the API that's in this subject area is WebAssemblyHttpMessageHandlerOptions.DefaultCredentials which is still supported and does work, but is not quite the same thing since it's a global static value, not something you can set per-request.

I've added a note about the need to reintroduce an API similar to this: https://github.com/aspnet/AspNetCore/issues/17043#issuecomment-558241317.

All 9 comments

Thanks @aguacongas

@mkArtakMSFT @danroth27 I'll need some guidance on this one given that the current content/approach was supplied initially for the topic by engineering and then later checked/approved by engineering for 3.0.

I've prioritized this one for a fast update once I have your guidance on it.

@SteveSandersonMS Is this just a product bug that we should fix?

@SteveSandersonMS, @pranavkm is this a product bug, that we need to move to the AspNetCore repo to track?

This is being tracked via https://github.com/mono/mono/issues/17808.

Am thinking this really is not a mono bug here. I think the problem is that the AspNetCore is still passing the value of FetchCredentialsOption from their implementation instead of from the WebAssembly Http Message Handler. Could someone verify that from your side?

Or maybe I am misunderstanding the current functionality. Could someone explain this or provide a repro with example?

@SteveSandersonMS @danroth27

@kjpou1 As far as I can tell, the current version of Mono doesn't provide any per-request way to set a credentials option. The credentials option is always set to the value of the globally static DefaultCredentials property: https://github.com/mono/mono/blob/5d981c267981505f425826ae0a3cc79dd08ecde4/sdks/wasm/framework/src/WebAssembly.Net.Http/WasmHttpMessageHandler.cs#L76. Do you think at some point it will be possible to reintroduce support for setting the credentials option on a per-request basis?

@aguacongas I'm afraid the docs you're pointing to are out of date, as is the code sample you've posted. You're referring to a type WebAssemblyHttpMessageHandler that doesn't exist in current versions of Blazor (or the underlying Mono WebAssembly runtime). It doesn't look to me like your workaround would work with the current framework. Or if I'm missing something about where this type is defined, please let me know!

@guardrex Could we remove the section of the docs that talks about FetchCredentialsOption being put into a Properties dictionary? Currently the only thing in the API that's in this subject area is WebAssemblyHttpMessageHandlerOptions.DefaultCredentials which is still supported and does work, but is not quite the same thing since it's a global static value, not something you can set per-request.

I've added a note about the need to reintroduce an API similar to this: https://github.com/aspnet/AspNetCore/issues/17043#issuecomment-558241317.

... and it looks like setting the referrer here was also dropped at some point since the topic was written. I'll 🔪 that, too.

https://github.com/aspnet/AspNetCore/blob/master/src/Components/test/testassets/BasicTestApp/HttpClientTest/HttpRequestsComponent.razor

@SteveSandersonMS you're right, it's not a workaround anymore since 3.1-preview3. This issue was open before.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

royshouvik picture royshouvik  Â·  3Comments

danroth27 picture danroth27  Â·  3Comments

davisnw picture davisnw  Â·  3Comments

madelson picture madelson  Â·  3Comments

sonichanxiao picture sonichanxiao  Â·  3Comments