jamiewest / signalr_core

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

Cannot connect to Azure SignalR Service #48

Closed janjoosse closed 3 years ago

janjoosse commented 3 years ago

Describe the bug

I am using the package to connect to Azure SignalR Service. The negotiate endpoint on my .NET Core app is working as expected, returning a 200 OK and the corresponding url and access token, which are then used by this package to connect to Azure SignalR Service.

However, while making the connection I run in the following error, it looks like it's failing because of a type cast failure.

flutter: Starting HubConnection.
flutter: Starting connection with transfer format 'TransferFormat.text'.
flutter: Sending negotiation request: https://localhost:5001/messagehub/negotiate.
flutter: Sending negotiation request: https://*******.service.signalr.net/client/negotiate?hub=messagehub&asrs.op=%2Fmessagehub&asrs_request_id=0D%2Bm4VE2AAA%3D.
flutter: Selecting transport 'HttpTransportType.webSockets'.
flutter: (WebSockets transport) Connecting.
flutter: Failed to start the transport 'HttpTransportType.webSockets': type 'Future<String?>' is not a subtype of type 'FutureOr<String>' in type cast
flutter: Skipping transport 'HttpTransportType.serverSentEvents' because it was disabled by the client.
flutter: Skipping transport 'HttpTransportType.longPolling' because it was disabled by the client.
flutter: The HttpConnection connected successfully.
flutter: Sending handshake request.
flutter: Hub handshake failed with error 'Exception: WebSocket is not in the OPEN state' during start(). Stopping HubConnection.

Expected behavior To succeed in making a connection.

I have created a Flutter project which can be used to reproduce the bug: https://github.com/janjoosse/SignalR_Core. Obviously reproducing it requires an Azure SignalR Service and backend API to get the url and accessToken to connect to Azure SignalR Service.

Does someone know what is causing this failure?

janjoosse commented 3 years ago

Opened a PR with a fix for this issue. With the fix the AccessTokenFactory is working like expected again, and the accesstoken is added as query param in the call to Azure SignalR Service.