jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 58 forks source link

Exception: The underlying connection was closed before the hub handshake could complete. #104

Open mamaly12 opened 11 months ago

mamaly12 commented 11 months ago

Hi there,

I still have the same issue. I use IdentityServer 4, and the following setup is recommended for signal authentication using the access token(according to https://learn.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-7.0#identity-server-jwt-authentication).

It's not related to the OS, and I am suspicious it's related to the library that cannot update the connection.

  var originalOnMessageReceived = options.Events.OnMessageReceived;
            options.Events.OnMessageReceived = async context =>
            {
                await originalOnMessageReceived(context);

                if (string.IsNullOrEmpty(context.Token))
                {
                    var accessToken = context.Request.Query["access_token"];
                    var path = context.HttpContext.Request.Path;

                    if (!string.IsNullOrEmpty(accessToken) &&
                        path.StartsWithSegments("/hubs"))
                    {
                        context.Token = accessToken;
                    }
                }
            };

When I start a socket connection request, everything seems fine, and the " context.Token" will be set according to the token. Still, suddenly, I received the error "The underlying connection was closed before the hub handshake could complete." from Flutter and my connection will be closed

dromerolovo commented 3 weeks ago

Hi @mamaly12 Can you provide your auth pipeline also, and your Hub implementation?