diff --git a/src/Microsoft.AspNetCore.Sockets/Connection.cs b/src/Microsoft.AspNetCore.Sockets/Connection.cs index f46b051953..f1c0c759e1 100644 --- a/src/Microsoft.AspNetCore.Sockets/Connection.cs +++ b/src/Microsoft.AspNetCore.Sockets/Connection.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Claims; using System.Threading.Tasks; using Channels; @@ -9,6 +10,7 @@ namespace Microsoft.AspNetCore.Sockets public class Connection { public string ConnectionId { get; set; } + public ClaimsPrincipal User { get; set; } public IChannel Channel { get; set; } public IDictionary Metadata { get; } = new Dictionary(); } diff --git a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs index f93504bb17..0843a9bc62 100644 --- a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs @@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Sockets { // Get the connection state for the current http context var connectionState = GetOrCreateConnection(context); + connectionState.Connection.User = context.User; connectionState.Connection.Metadata["transport"] = "sse"; var sse = new ServerSentEvents(connectionState.Connection); @@ -76,6 +77,7 @@ namespace Microsoft.AspNetCore.Sockets { // Get the connection state for the current http context var connectionState = GetOrCreateConnection(context); + connectionState.Connection.User = context.User; connectionState.Connection.Metadata["transport"] = "websockets"; var ws = new WebSockets(connectionState.Connection); @@ -126,7 +128,7 @@ namespace Microsoft.AspNetCore.Sockets if (isNewConnection) { connectionState.Connection.Metadata["transport"] = "poll"; - + connectionState.Connection.User = context.User; // REVIEW: We should await this task after disposing the connection var ignore = endpoint.OnConnected(connectionState.Connection); }