Skip to content
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

Reconnection switch url as I needed to pass in access token (JWT) as url query string. #121

Open
Lewis-Teoh opened this issue Oct 12, 2022 · 2 comments

Comments

@Lewis-Teoh
Copy link

Hi, is there any way to pass in JWT token as url query string parameter during reconnection happen? As time to time the client might have disconnected and JWT token will be expired, so I need to pass in a new token when reconnection happen.

@Jericho
Copy link

Jericho commented Oct 12, 2022

I have the exact same scenario: The 3rd-party system I connect to mandates that I include a token on the querystring and this token expires at regular intervals. Therefore, I must obtain a new token and change the URL from time to time. Fortunately, I can achieve this with the websocket-client client factory like so:

var clientFactory = new Func<Uri, CancellationToken, Task<WebSocket>>(async (uri, cancellationToken) =>
{
	// The current value in the uri parameter must be ignored because it contains "access_token" which may or may not be expired.
	// The following line ensures the "access_token" is refreshed whenever it expires.
	uri = new Uri($"wss://ws.zoom.us/ws?subscriptionId={_subscriptionId}&access_token={_tokenHandler.Token}");

	var client = new ClientWebSocket()
	{
		Options =
		{
			KeepAliveInterval = TimeSpan.Zero, // Turn off built-in "Keep Alive" feature because Zoom uses proprietary "heartbeat" every 30 seconds rather than standard "pong" messages at regular interval.
		}
	};
	client.Options.SetRequestHeader("ZoomNet-Version", ZoomClient.Version);

	await client.ConnectAsync(uri, cancellationToken).ConfigureAwait(false);
	return client;
});

// Please note that the url specified on the following line will be ignored and will be replaced with the URI calculated in the client factory
var myWebsocketClient = new WebsocketClient(new Uri("wss://ws.zoom.us"), clientFactory);

Hope this helps

@Lewis-Teoh
Copy link
Author

Woah! Thanks for the help! It works well :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants