My current infrastructure contains a nodeJS hosted React-UI which uses SignalR to connect to an ASP.Net Core SignalR-Hub with Cookie-Authentication.
After deployment my UI wasn't able to connect to the API-HubEndpoints due to CORS related problems. I solved this by setting up a proxy (URL of the API) inside my package.json. The next problem was that the set-cookie was declined clientside because of security reasons (unsecure connection / HTTP).
So I ran the ReactJS application though https (w/o certificate) using set HTTPS=true&&npm start and activated SSL on the ASP.Net Core API server. Now receiving and storing the cookie works fine. The cookie is also send when connecting to the Hub-Endpoint (withCredentials).
Now to my problem:
Server log says that negotiation was successfully completed and is about to send negotations response but response never reaches the client and keeps the HubConnection in connecting-State.
Steps to reproduce
- Create React Application
- Create ASP.NET Core API Server with SSL, CORS, SignalR and cookie-authentication
- Create a login-mechanism with cookie.
- Setup Proxy in your Reacts package.json
- Visit your UI from different machine than the hosting one
- Use your Login mechanism to receive cookie
- Connect HubConnection to Hub-Endpoint with received cookie
Some Logs from Client and server
Client
[2022-05-16T12:23:09.588Z] Information: Normalizing '/hubs/system' to 'https://localhost:3000/hubs/system'.
[2022-05-16T12:23:09.589Z] Debug: Starting HubConnection.
[2022-05-16T12:23:09.590Z] Debug: Starting connection with transfer format 'Binary'.
[2022-05-16T12:23:09.591Z] Debug: Sending negotiation request: https://localhost:3000/hubs/system/negotiate?negotiateVersion=1.
[2022-05-16T12:23:29.991Z] Debug: Selecting transport 'WebSockets'.
[2022-05-16T12:23:29.992Z] Trace: (WebSockets transport) Connecting.
[2022-05-16T12:35:19.818Z] Information: (WebSockets transport) There was an error with the transport.
[2022-05-16T12:35:19.818Z] Information: (WebSockets transport) There was an error with the transport.
[2022-05-16T12:35:19.820Z] Debug: Skipping transport 'LongPolling' because it was disabled by the client.
[2022-05-16T12:35:19.821Z] Debug: HubConnection failed to start successfully because of error 'Error: Unable to connect to the server with any of the available transports. Error: WebSockets failed: Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled. ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. LongPolling failed: Error: 'LongPolling' is disabled by the client.'.
Server
Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager: Debug: New connection 1Fw27F0X22O7jVuoWoejug created.
Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher: Debug: Sending negotiation response.