Add User to Connection
This commit is contained in:
parent
8e66d63577
commit
99d7aea78c
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
using Channels;
|
||||||
|
|
||||||
|
|
@ -9,6 +10,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
public class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
public string ConnectionId { get; set; }
|
public string ConnectionId { get; set; }
|
||||||
|
public ClaimsPrincipal User { get; set; }
|
||||||
public IChannel Channel { get; set; }
|
public IChannel Channel { get; set; }
|
||||||
public IDictionary<string, string> Metadata { get; } = new Dictionary<string, string>();
|
public IDictionary<string, string> Metadata { get; } = new Dictionary<string, string>();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
// Get the connection state for the current http context
|
// Get the connection state for the current http context
|
||||||
var connectionState = GetOrCreateConnection(context);
|
var connectionState = GetOrCreateConnection(context);
|
||||||
|
connectionState.Connection.User = context.User;
|
||||||
connectionState.Connection.Metadata["transport"] = "sse";
|
connectionState.Connection.Metadata["transport"] = "sse";
|
||||||
var sse = new ServerSentEvents(connectionState.Connection);
|
var sse = new ServerSentEvents(connectionState.Connection);
|
||||||
|
|
||||||
|
|
@ -76,6 +77,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
// Get the connection state for the current http context
|
// Get the connection state for the current http context
|
||||||
var connectionState = GetOrCreateConnection(context);
|
var connectionState = GetOrCreateConnection(context);
|
||||||
|
connectionState.Connection.User = context.User;
|
||||||
connectionState.Connection.Metadata["transport"] = "websockets";
|
connectionState.Connection.Metadata["transport"] = "websockets";
|
||||||
var ws = new WebSockets(connectionState.Connection);
|
var ws = new WebSockets(connectionState.Connection);
|
||||||
|
|
||||||
|
|
@ -126,7 +128,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
if (isNewConnection)
|
if (isNewConnection)
|
||||||
{
|
{
|
||||||
connectionState.Connection.Metadata["transport"] = "poll";
|
connectionState.Connection.Metadata["transport"] = "poll";
|
||||||
|
connectionState.Connection.User = context.User;
|
||||||
// REVIEW: We should await this task after disposing the connection
|
// REVIEW: We should await this task after disposing the connection
|
||||||
var ignore = endpoint.OnConnected(connectionState.Connection);
|
var ignore = endpoint.OnConnected(connectionState.Connection);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue