Force access token refresh in oauth2?
I’m consuming the oauth2 package to login and maintain authorization in an api. It works perfectly with http requests. The client auto refreshes the access token using the refresh token if the access token is expired. My logic refreshes both tokens if the refresh token gets near the end of lifespan. Absolutely no problem, everything works perfectly.
Have lately added a websocket connection. It uses the access token to create a connection. Adds subscriptions that also use access tokens. Absolutely no problem either. As long as http requests no problemo.
But, I need to refresh the access token to reauthorize the websocket connection near the end of the access token’s life span. This needs to be done before the current access token expires. The fresh access token is then used to reauthorize the websocket connection.
Currently I try to do this about one minute before the access token expires. I use the same code snippet as is used to refresh both tokens if the refresh token gets near expiration. This method does not seem to work as the old, near expiration token is returned. Maybe the access token needs to be expired for this routine to work?
Is there a way to force tokenSource.Token() to refresh tokens before an access token has expired? Or does anyone have any alternative method to implement this use case? Can the token expiry be changed to manipulate the tokenSource to run a refresh?