Refresh OAuth Token on websocket

I am currently creating a bot that listens for channel point redemption on a specific channel, once the script is initialized it gets a fresh auth_token using the refresh token, however these tokens have an expiration of I believe one hour. Some streaming sessions might last longer so the token will expire after the hour, would sending a new message with a new oauth token before the end of the hour work for refreshing or would I have to close the current socket and open a new one?

Should be four hours for a regular user token.

For pubsub? No.

When the access token has expired (or close to expire)
Just use the refresh token to get a new token
Then just LISTEN (again) using the existing token. (may want to UNLISTEN first to prevent dupes/weirdness)
So no need to destory the old socket.

Or start a new socket with the new token + listen requests.
Then when that has finished connecting close the old socket.

I have a method in my Bot class that sends a message, would the message sent be something like this?

data = json.dumps({
				"type": "LISTEN",
				"nonce": str(nonce),
				"data": {
				"topics": ["channel-points-channel-v1."+str(self.channel_id)],
				"auth_token": self.access_token}
				})
			await self.sendMessage(data)

where self.access_token is the refreshed token.

It is identical to the LISTEN command you sent on initial connecting, it’s just with the new token.
So yes.

1 Like