question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR - CORS - Windows Authentication it fails to get past negotiate - NOT SOLVED - IT IS A BUG till MS SOLVES ISSUE!

See original GitHub issue

Describe the bug

When trying to set up connection to Hub it always fails, HOWEVER all of the standard API controller calls work and negotiate just fine, it only fails when trying to connect to the Hub using this library that MS provides:

const newConnection = new HubConnectionBuilder() .withUrl(url, options => { options.UseDefaultCredentials = true options.Headers[‘Content-Type’] = ‘text/plain’ // options.SkipNegotiation = true; })
.withAutomaticReconnect() .build();

I have tried many different configurations of this call and still nothing.

Have added to web.config this did help a little, it at least lets me in, but still fails with exception below:

 <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="https://localhost:3000" />       
          <add name="Access-Control-Allow-Credentials" value="true" />
          <add name="Access-Control-Request-Headers" value="User-Agent,Content-Type,Authorization,X-RequestDigest,X-ClientService-ClientTag,XMLHttpRequest,x-requested-with" />
          <add name="Access-Control-Allow-Headers" value="User-Agent,Content-Type,Authorization,X-RequestDigest,X-ClientService-ClientTag,XMLHttpRequest,x-requested-with" />
          <add name="Access-Control-Request-Method" value="GET,POST,HEAD,OPTIONS" />
        </customHeaders>
      </httpProtocol>

Also tried custom middleware for CORS but still failing with or without it. Of course it is blocking the request before it gets to actual hub. Have tried skipping Negotiation, but that has not worked either. Get the same error on DEV box also, so it seems consistent with of course a different Access-Control-Allow-Origin.

Exceptions (if any)

Access to fetch at ‘https://localhost:44319/ticketsummary/negotiate?negotiateVersion=1’ from origin ‘https://localhost:3000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

image

Further technical details

dotnet core 3.1

  • SSL enabled
  • Win Auth enabled

SignalR reactJS

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Jun 30, 2021

This is outside the scope of what we can support through GitHub. You can reach out to paid support at http://support.microsoft.com/supportforbusiness/productselection?sapId=ef53b119-5f8c-7343-2a0f-f5008a1399b9

1reaction
pthorsleycommented, Jun 29, 2021

The localSpecificOrigins is what is run when debugging, have removed serverSpecificOrigins just for this testing fix.

Might try out Socket.io , maybe it does not have this CORS, SignalR, Win Auth issue.

Here is the basic add CORS options:

public void ConfigureServices(IServiceCollection services)
       {
         
           services.AddSignalR();

           services.AddControllers();

           services.Configure<AppSettings>(Configuration);

           services.AddMemoryCache();

           services.Configure<IISOptions>(options => options.AutomaticAuthentication = true);

           services.AddScoped<SmtpClient>((serviceProvider) =>
           {
               var config = serviceProvider.GetRequiredService<IConfiguration>();
               return new SmtpClient()
               {
                   Host = config.GetValue<String>("EmailSettings:SMTP:Host"),
                   Port = config.GetValue<int>("EmailSettings:SMTP:Port"),
                   UseDefaultCredentials = false,
               };
           });
services.AddCors(options =>
           {
               options.AddPolicy(localSpecificOrigins,
               builder =>
               {
                   builder.WithOrigins("http://localhost:3000", "http://localhost:3001", "https://localhost:3000", "https://localhost:3001")
                   .AllowAnyHeader()
                   .AllowAnyMethod()
                   .AllowCredentials()
                   .SetIsOriginAllowed((host) => true) ;
               });

               options.AddPolicy(serverSpecificOrigins,
               builder =>              
               {
                   builder.WithOrigins("<server list removed for github>")
                   .AllowAnyHeader()
                   .AllowAnyMethod()
                   .AllowCredentials()
                   .SetIsOriginAllowed((host) => true);
               });
           });

       services.AddAuthentication(IISDefaults.Ntlm);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR client CORS error when using Windows ...
The error I am receiving is the following one: Access to XMLHttpRequest at 'http://localhost:2110/api/aircrafts/hub/negotiate' from origin 'http ...
Read more >
SignalR Troubleshooting
This error may be seen if authentication is being used, and the client is logged out before the connection is stopped. The solution...
Read more >
Negotiation call from React TypeScript client webapp to ...
Negotiation call from React TypeScript client webapp to Azure SignalR service is giving CORS error in browser and 403 forbidden in Postman.
Read more >
Resolved: SignalR Error: Failed To Complete Negotiation ...
This blog provides a solution to the signalR hub connection issue such as Error: Failed to complete negotiation with the server: Error: Not...
Read more >
Troubleshooting guide for Azure SignalR Service
This article provides troubleshooting guidance for some of the common issues that customers might encounter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found