From 7cf06c15546ab65e251c01a779d37613bb51e3c7 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:48:45 -0500 Subject: [PATCH] Blazor WASM configure SignalR client (#18742) --- .../blazor/hosting-model-configuration.md | 33 ++++++++++++++++++- aspnetcore/blazor/progressive-web-app.md | 6 +++- .../tutorials/signalr-blazor-webassembly.md | 3 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/aspnetcore/blazor/hosting-model-configuration.md b/aspnetcore/blazor/hosting-model-configuration.md index 4a3050eed4..bd7ed48e52 100644 --- a/aspnetcore/blazor/hosting-model-configuration.md +++ b/aspnetcore/blazor/hosting-model-configuration.md @@ -5,7 +5,7 @@ description: Learn about Blazor hosting model configuration, including how to in monikerRange: '>= aspnetcore-3.1' ms.author: riande ms.custom: mvc -ms.date: 05/28/2020 +ms.date: 06/10/2020 no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR] uid: blazor/hosting-model-configuration --- @@ -281,6 +281,37 @@ For more information on how background updates are handled by PWAs, see . +### SignalR cross-origin negotiation for authentication + +To configure SignalR's underlying client to send credentials, such as cookies or HTTP authentication headers: + +* Use to set on cross-origin [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch) requests: + + ```csharp + public class IncludeRequestCredentialsMessagHandler : DelegatingHandler + { + protected override Task SendAsync( + HttpRequestMessage request, CancellationToken cancellationToken) + { + request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); + return base.SendAsync(request, cancellationToken); + } + } + ``` + +* Assign the to the option: + + ```csharp + var client = new HubConnectionBuilder() + .WithUrl(new Uri("http://signalr.example.com"), options => + { + options.HttpMessageHandlerFactory = innerHandler => + new IncludeRequestCredentialsMessagHandler { InnerHandler = innerHandler }; + }).Build(); + ``` + +For more information, see . + ## Blazor Server ### Reflect the connection state in the UI diff --git a/aspnetcore/blazor/progressive-web-app.md b/aspnetcore/blazor/progressive-web-app.md index a37ede5df4..d5124bbd3b 100644 --- a/aspnetcore/blazor/progressive-web-app.md +++ b/aspnetcore/blazor/progressive-web-app.md @@ -5,7 +5,7 @@ description: Learn how to build a Blazor-based Progressive Web Application (PWA) monikerRange: '>= aspnetcore-3.1' ms.author: riande ms.custom: mvc -ms.date: 06/09/2020 +ms.date: 06/10/2020 no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR] uid: blazor/progressive-web-app --- @@ -281,3 +281,7 @@ The [CarChecker](https://github.com/SteveSandersonMS/CarChecker) sample app demo * `OfflineAccountClaimsPrincipalFactory` (*Client/Data/OfflineAccountClaimsPrincipalFactory.cs*) * `LocalVehiclesStore` (*Client/Data/LocalVehiclesStore.cs*) * `LoginStatus` component (*Client/Shared/LoginStatus.razor*) + +## Additional resources + +* [SignalR cross-origin negotiation for authentication](xref:blazor/hosting-model-configuration#signalr-cross-origin-negotiation-for-authentication) diff --git a/aspnetcore/tutorials/signalr-blazor-webassembly.md b/aspnetcore/tutorials/signalr-blazor-webassembly.md index 5946252667..51a3012c55 100644 --- a/aspnetcore/tutorials/signalr-blazor-webassembly.md +++ b/aspnetcore/tutorials/signalr-blazor-webassembly.md @@ -5,7 +5,7 @@ description: Create a chat app that uses ASP.NET Core SignalR with Blazor WebAss monikerRange: '>= aspnetcore-3.1' ms.author: riande ms.custom: mvc -ms.date: 05/19/2020 +ms.date: 06/10/2020 no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR] uid: tutorials/signalr-blazor-webassembly --- @@ -285,3 +285,4 @@ To learn more about building Blazor apps, see the Blazor documentation: ## Additional resources * +* [SignalR cross-origin negotiation for authentication](xref:blazor/hosting-model-configuration#signalr-cross-origin-negotiation-for-authentication)