【问题标题】:Configure Claims mapping to hubContext.Clients.User in Azure SignalR在 Azure SignalR 中配置到 hubContext.Clients.User 的声明映射
【发布时间】:2019-11-21 11:57:13
【问题描述】:

我正在尝试像这样使用 Azure SignalR 向特定用户发送消息

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

根据https://docs.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-3.0 默认情况下,Signalr 使用 ClaimTypes.NameIdentifier 来识别用户。

我可以更改此默认设置以改用 ClaimTypes.EmailClaim 吗?这是可配置的吗?

【问题讨论】:

    标签: azure azure-webjobs azure-signalr


    【解决方案1】:

    对于 .NetCore 应用程序。这种方法有效

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

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 2010-10-22
      • 2022-11-02
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 2021-05-19
      相关资源
      最近更新 更多