Signal R not sending Notifications To Specific User ClaimTypes.NameIdentifier with B2C Authentication

Viewed 62

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?}");
            });
1 Answers

I see:

options.TokenValidationParameters.NameClaimType = "name";

But then the use of ClaimTypes.NameIdentifier (which SignalR uses by default).

I would just verify these are consistent and correct.

Related