79688550

Date: 2025-07-03 08:51:04
Score: 1.5
Natty:
Report link

Late to the party but for other having the same problem. For me the following worked:

I changed my code from this:

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
             .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));

to this:

// Add services to the container.
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(options =>
    {
        builder.Configuration.Bind("AzureAd", options);
        
        // Configure events for SignalR
        options.Events = new JwtBearerEvents
        {
            OnMessageReceived = context =>
            {
                // Check if the request is for SignalR and has a query string token
                if (context.Request.Path.StartsWithSegments("/syncProgressHub") &&
                    context.Request.Query.ContainsKey("access_token"))
                {
                    // Read the access token from the query string
                    context.Token = context.Request.Query["access_token"];
                }
                return Task.CompletedTask;
            }
        };
    }, 
    options => builder.Configuration.Bind("AzureAd", options));
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): having the same problem
  • Low reputation (0.5):
Posted by: bslein