oauth2 icon indicating copy to clipboard operation
oauth2 copied to clipboard

Token expiration tolerance should be configurable

Open CSEMike opened this issue 7 years ago • 7 comments

The expiryDelta used to calculate token validity is fixed at 10 seconds. https://github.com/golang/oauth2/blob/master/token.go#L21

This issue tracks making this value configurable. Why? To support scenarios where the token may be not be used until >10s in the future.

Token validity is used to refresh cached values, e.g., https://github.com/golang/oauth2/blob/master/oauth2.go#L260

An alternative API would be to support invalidation of the token cache. But, in either case, a way to configure the max acceptable age of a token is necessary to avoid corner cases when expiration is near.

CSEMike avatar Aug 31 '17 22:08 CSEMike

👍 for the issue.

My usecase is to force refresh stored tokens and I need to have custom expiryDelta.

Another possible solution might be to expose tokenRefresher, so one would have much more control over the refreshment process.

narqo avatar Oct 24 '17 14:10 narqo

I've opened a PR that would accommodate this issue here: https://github.com/golang/oauth2/pull/396

fharding1 avatar Sep 03 '19 20:09 fharding1

This is really needed. Some OAuth services have expiry of access token=refresh token which makes using standard library oauth impossible.

andig avatar Jul 03 '23 15:07 andig

An alternative API would be to support invalidation of the token cache. But, in either case, a way to configure the max acceptable age of a token is necessary to avoid corner cases when expiration is near.

Yet another option would be to expose the capability to refresh the token on demand. If you consider the case above I'd still need to trigger token requests within the expiry delta to actually refresh. Could as well just invoke the exposed Refresh() capability.

andig avatar Jul 03 '23 15:07 andig

Note: this issue actually looks a lot like https://github.com/golang/oauth2/commit/4abfd87339731bbbde108264890e9636453bf0f9.

/cc @codyoss @rolandshoemaker any chance to move this forward?

andig avatar Jul 03 '23 15:07 andig

Going through the commits it seems we could already do this with https://github.com/golang/oauth2/commit/1e7f32936487c0d8052d63fd32d84f4c1121986e.

andig avatar Jul 03 '23 15:07 andig

That said: looks like this issue could be closed @CSEMike

andig avatar Jul 03 '23 16:07 andig