dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.64k stars 25.29k forks source link

Signalr Core Blazor Client #32629

Closed B-Richie closed 6 months ago

B-Richie commented 6 months ago

Before you open an issue

If the issue is with an ASP.NET Core document:

Using the Open a documentation issue link and form to open an issue adds article metadata for tracking, which indicates the article that you're commenting on.

If the issue is:

Issue description

Blazor Web App SignalR Client requires an access token yet I cannot obtain it inside a Blazor razor component

Software versions

Check the .NET target framework(s) being used, and include the version number(s).

If using the .NET Core SDK, include dotnet --info output. If using .NET Framework without the .NET Core SDK, include info from Visual Studio's Help > About Microsoft Visual Studio dialog.

dotnet --info output or About VS info I need to pass in my access token via the AccessTokenProvider when building my hub connection builder: hubConnection = new HubConnectionBuilder() .WithUrl(Navigation.ToAbsoluteUri("https://localhost:7288/chathub"), options => { options.AccessTokenProvider = () => Task.FromResult(signalRToken); <= here options.Headers.Add("BusinessId", MapInitialization!.BusinessId!.Value!.ToString()); options.Headers.Add("BusinessRole", MapInitialization?.SignalRRole!); options.Headers.Add("DisplayName", MapInitialization?.SignalRDisplayName!); options.Headers.Add("UserName", MapInitialization?.SignalRUserName!); }).Build(); I can't find a way to obtain my access token in my cookie. I tried injecting the AuthenticationStateProvider, cascading an AuthenticationState parameter, cascading a HttpContext parameter, and cascading a HttpContextAccessor property but neither contains my cookie information. ```console ```
guardrex commented 6 months ago

Hello @B-Richie ... It would be best to have opened this from the bottom of the Fundamentals > SignalR article or the Server > Additional Scenarios article in the Security node. It adds metadata to the issue and pings me.

No worries tho on metadata, etc. This issue is a duplicate of https://github.com/dotnet/AspNetCore.Docs/issues/31691.