3

We recently did an update of our code on the server side to asp.net core 3.1. Now there is a problem with the java-script client for signalr (@microsoft/signalr 3.1.0).

I get the following errors:

enter image description here

The code for the hub initialization:

enter image description here

The access token factory returns the token from msal. (There were no changes made to the authentication and the token is received correctly there) Would be great if someone could help me with this.

  • Did you tried other transports? – Kiril1512 Feb 10 '20 at 09:53
  • Yes I did and I just saw that long polling is working. But I'd prefere using WebSockets. But why is transport over WebSockets not working anymore? The only thing that I know, has changed, is that the Hub is using Newtonsoft Json protocol. @Kiril1512 – Simon Lüscher Feb 10 '20 at 10:09
  • Did you have on your startup ```app.UseWebSockets();```? – Kiril1512 Feb 10 '20 at 14:55

2 Answers2

1

I'm using @aspnet/signalr javascript client - same version as the Nuget of server. Don't know why, but could not get it work with @microsoft/signalr.

Check your startup, for me the authentication failed because I've forgot to add AllowCredentials on Cors:

public void ConfigureServices(IServiceCollection services)
{
        services
            .AddControllers();
        services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
        {
            builder
                .AllowAnyMethod() //edit on your requirements
                .AllowAnyHeader() //edit on your requirements
                .AllowAnyOrigin() //edit on your requirements
                .AllowCredentials();
        }));
        services.AddSignalR();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();
}
user1519979
  • 1,854
  • 15
  • 26
1

I was getting the same error, and eventually the problem was with the length of the access_token that it is passed in the query parameter see this issue query string is too long with big bearer token attached in the URL.

So in order to solve it check this answer

Kardon63
  • 337
  • 1
  • 5
  • 18