jamiewest / signalr_core

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

Cannot start connection with server that requires authentication #20

Closed zuboje closed 3 years ago

zuboje commented 4 years ago

I have piece of code:

final hubConnection = HubConnectionBuilder() .withUrl( serverUrl, HttpConnectionOptions( accessTokenFactory: () => _secureStorage.read(key: 'bearerToken'), logging: (level, message) => print(message), )) .build();

await hubConnection.start();

My Hub connection variable always show that _accessTokenFactory is null, that function is never called. I tried creating separate function like:

Future getAccessToken() async{ var token = await _secureStorage.read(key: 'bearerToken'); return token; }

and calling it like this:

... accessTokenFactory: () => _getAccessToken(), ...

Putting debug point on "var token..." and it is never called, this function is never executed. Looking deeper into this, the only place that actually uses "accessTokenFactory" is "utils.dart" under "sendMessage" future. Problem is that connection cannot be established with the server without token. I have tested signalr server with simple client in .net and if I provide access token in hubconnection my server works and responds.

jamiewest commented 4 years ago

I have not had time to run your sample but I am looking at this:

accessTokenFactory() => _getAccessToken()

I would see if your only getting the Future because it is not async/await'd. Or you are getting it, but synchronously. Could you try that out and see if you get a better result?

zuboje commented 3 years ago

The issue was on my end. My apology for the long delay I had to work on different areas of the app on my end to get back to this one. It was a server problem, not a plugin problem.