Skip to content

SignalR Client Windows Authentication returning 401Unautorized (update 6.0.11 -> 7.0.0) #45371

Closed

Description

@LH-EA

Description

After updating the version of Microsoft.AspNetCore.SignalR.Client from 6.0.11 to 7.0.0 I receive a 401 (Unauthorized) when trying to start the connection using default credentials. I couldn't find any information about potential breaking changes.

  connection = new HubConnectionBuilder()
  .WithUrl(hubUrl, options => {
      options.UseDefaultCredentials = true;
  }).WithAutomaticReconnect().Build();
    
   await connection.StartAsync(); ---> Response status code does not indicate success: 401 (Unauthorized).

Configuration

VS2022
.NET 7
Windows 10
x64
All Browsers

Activity

  1. transferred this issue fromdotnet/coreon Nov 30, 2022
  2. BrennanConroy commented on Nov 30, 2022

    @BrennanConroy
    Member

    We didn't change much on the client side from 6.0 to 7.0, did you update the server at the same time? Can you try only updating one side at a time and seeing what combo creates the issue?

  3. added
    area-signalr
    on Nov 30, 2022
  4. added
    Needs: Author Feedback
    on Dec 2, 2022
  5. LH-EA commented on Dec 5, 2022

    @LH-EA
    Author

    I upgraded server-side from 6.0.11. ---> 7.0.0 too. I downgraded the server, keeping client version at 7.0.0. The issue persisted. Now, with SignalR-Server version 7.0.0 and Client version 6.0.11 it is working, so I assumed the problem was in the new version of the client lib

  6. ghost added
    Needs: Attention 👋
    on Dec 5, 2022
  7. ghost removed
    Needs: Author Feedback
    on Dec 5, 2022
  8. BrennanConroy commented on Dec 5, 2022

    @BrennanConroy
    Member

    Oh I have an idea of what's happening. I don't think Windows Auth works over HTTP2, but because the HttpClient is trying HTTP2 by default now it will successfully connect but fail any requests that require windows auth.

    Try:

    private class Http11Handler : DelegatingHandler
    {
        public Http11Handler(HttpMessageHandler handler)
            : base(handler)
        { }
    
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Version = HttpVersion.Version11;
            return base.SendAsync(request, cancellationToken);
        }
    }
    
    HubConnection CreateConnection()
    {
        return new HubConnectionBuilder().WithUrl(url, options =>
        {
            options.UseDefaultCredentials = true;
            options.HttpMessageHandlerFactory = handler =>
            {
                return new Http11Handler((HttpClientHandler)handler);
            };
        }).Build();
    }

    Related issue: dotnet/runtime#1582

  9. adityamandaleeka commented on Dec 5, 2022

    @adityamandaleeka
    Member

    Triage: We could consider servicing this in 7.0 by looking for UseDefaultCredentials = true and then forcing the protocol back down to 1.1.

  10. LH-EA commented on Dec 7, 2022

    @LH-EA
    Author

    Yes this worked. Thanks for the workaround!

  11. added this to the 7.0.x milestone on Dec 7, 2022
  12. removed
    Needs: Attention 👋
    on Dec 7, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-signalr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions