Signal R 未通过 B2C 身份验证向特定用户 ClaimTypes.NameIdentifier 发送通知
我正在使用 Azure B2C 在客户端进行身份验证。当我尝试调用发送通知时,它没有发送通知。
public async Task SendNotifications(IEnumerable<NotificationServiceModel> notifications)
{
foreach (NotificationServiceModel notification in notifications)
{
string userId= httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
await hubContext.Clients.User(userId).SendAsync(ReceiveNotification, notification);
}
}
我正在使用 Azure b2c 身份验证,其中包含 UserId,
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(
options =>
{
Configuration.Bind("AzureAdB2C", options);
options.TokenValidationParameters.NameClaimType = "name";
},
options =>
{
Configuration.Bind("AzureAdB2C", options);
});
这里是 Hub 映射
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<NotificationsHub>("/api/notifications");
endpoints.MapHub<OutlookHub>("/api/outlook");
endpoints.MapHub<EventsHub>("/api/live/events");
endpoints.MapControllerRoute(
"default",
"{controller}/{action=Index}/{id?}");
});
I am using Azure B2C for authentication on Client Side. When I am trying to invoke the Send Notification it is not sending notification.
public async Task SendNotifications(IEnumerable<NotificationServiceModel> notifications)
{
foreach (NotificationServiceModel notification in notifications)
{
string userId= httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
await hubContext.Clients.User(userId).SendAsync(ReceiveNotification, notification);
}
}
I am using Azure b2c Authentication with claimType Name which contains UserId
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(
options =>
{
Configuration.Bind("AzureAdB2C", options);
options.TokenValidationParameters.NameClaimType = "name";
},
options =>
{
Configuration.Bind("AzureAdB2C", options);
});
here is Hub Mapping
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<NotificationsHub>("/api/notifications");
endpoints.MapHub<OutlookHub>("/api/outlook");
endpoints.MapHub<EventsHub>("/api/live/events");
endpoints.MapControllerRoute(
"default",
"{controller}/{action=Index}/{id?}");
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到:
但是然后使用
ClaimTypes.NameIdentifier
(SignalR 默认使用的)。我只是验证这些是否一致且正确。
I see:
But then the use of
ClaimTypes.NameIdentifier
(which SignalR uses by default).I would just verify these are consistent and correct.