You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix HubConnectionContext.UserIdentifier is null when negotiation with Management SDK
When clients negotiatie with Management SDK and connect to SignalR server, IUserIdProvider might not work as the user Id is set directly in the Management SDK.
To make HubConnectionContext.UserIdentifier have the valid value in this case, we should set it before the server can access it. HubLifetimeManager{THub}.OnConnectedAsync(HubConnectionContext) is the only chance we can set the value. However, we cannot access the Constants.ClaimType.UserId as ASRS system claims're trimmed there. HubConnectionContext.Features is the place where we can store the user Id.
The following code is our injection point.
https://github.com/dotnet/aspnetcore/blob/v6.0.9/src/SignalR/server/Core/src/HubConnectionHandler.cs#L132-L141
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+
usingMicrosoft.AspNetCore.SignalR;
5
+
6
+
namespaceMicrosoft.Azure.SignalR
7
+
{
8
+
/// <summary>
9
+
/// When clients negotiate with Management SDK and connect to SignalR server, the <see cref="IUserIdProvider"/> might not work as the user Id is set directly in the Management SDK.
10
+
/// To make <see cref="HubConnectionContext.UserIdentifier"/> have the valid value in this case, we should set it before the server can access it. <see cref="HubLifetimeManager{THub}.OnConnectedAsync(HubConnectionContext)"/> is the only chance we can set the value. However, we cannot access the <see cref="Constants.ClaimType.UserId"/> as ASRS system claims're trimmed there. <see cref="HubConnectionContext.Features"/> is the place where we can store the user Id.
0 commit comments