forked from soernt/signalr_client
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add a query string to the connection? #9
Comments
You can use accessTokenFactory, that adds token parameter to the query: void createHubConnection() async {
final httpConnectionOptions = new HttpConnectionOptions(
accessTokenFactory: () async => 'put_some_token_here',
logMessageContent: false);
_hubConnection = HubConnectionBuilder()
.withUrl(kHubConnectionURL, options: httpConnectionOptions);
await _hubConnection.start();
_hubConnection.invoke("tokenTest", args: <Object>[]);
} then on server you will be able to retrieve token as following: [HubMethodName("tokenTest")]
public async Task<string> TokenTest()
{
var request = Context.GetHttpContext().Request;
if (request.Query.ContainsKey("access_token"))
{
string token = request.Query["access_token"].FirstOrDefault();
//check user token here
}
} |
Is it possible to do this during the initial connection instead of invoking a method after the connection has already been established? |
@magnuswikhog await _hubConnection.start();
_hubConnection.invoke("tokenTest", args: <Object>[]); Does that suffice for your purpose? |
This was referenced Apr 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want my server to identify me, for example by my username. For that I need to pass my username when opening a connection, how to do that?
The text was updated successfully, but these errors were encountered: