diff --git a/aspnetcore/signalr/authn-and-authz.md b/aspnetcore/signalr/authn-and-authz.md index 5b7b2e4612..3e81462f8b 100644 --- a/aspnetcore/signalr/authn-and-authz.md +++ b/aspnetcore/signalr/authn-and-authz.md @@ -5,7 +5,7 @@ description: Learn how to use authentication and authorization in ASP.NET Core S monikerRange: '>= aspnetcore-2.1' ms.author: bradyg ms.custom: mvc -ms.date: 01/31/2019 +ms.date: 05/09/2019 uid: signalr/authn-and-authz --- @@ -19,6 +19,32 @@ By [Andrew Stanton-Nurse](https://twitter.com/anurse) SignalR can be used with [ASP.NET Core authentication](xref:security/authentication/identity) to associate a user with each connection. In a hub, authentication data can be accessed from the [`HubConnectionContext.User`](/dotnet/api/microsoft.aspnetcore.signalr.hubconnectioncontext.user) property. Authentication allows the hub to call methods on all connections associated with a user (See [Manage users and groups in SignalR](xref:signalr/groups) for more information). Multiple connections may be associated with a single user. +The following is an example of `Startup.Configure` which uses SignalR and ASP.NET Core authentication: + +```csharp +public void Configure(IApplicationBuilder app) +{ + ... + + app.UseStaticFiles(); + + app.UseAuthentication(); + + app.UseSignalR(hubs => + { + hubs.MapHub("/chat"); + }); + + app.UseMvc(routes => + { + routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); + }); +} +``` + +> [!NOTE] +> The order in which you register the SignalR and ASP.NET Core authentication middleware matters. Always call `UseAuthentication` before `UseSignalR` so that SignalR has a user on the `HttpContext`. + ### Cookie authentication In a browser-based app, cookie authentication allows your existing user credentials to automatically flow to SignalR connections. When using the browser client, no additional configuration is needed. If the user is logged in to your app, the SignalR connection automatically inherits this authentication.