简体   繁体   中英

Configure Claims mapping to hubContext.Clients.User in Azure SignalR

I am trying to Send a message to a particular User using Azure SignalR like this

await this.hubContext.Clients.User(UserId).SendAsync("NotifyUser", "message");

According to https://docs.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-3.0 By default Signalr uses ClaimTypes.NameIdentifier to identify the user.

Can I change this default setting to use ClaimTypes.EmailClaim instead? Is this Configurable?

For.NetCore app. This approach works

public class CustomUserIdentityProvider : IUserIdProvider
        {
        public string GetUserId(HubConnectionContext connection)
        {
            return connection.User.Claims.FirstOrDefault(x => x.Type == Constants.EmailClaim)?.Value;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM