Create new client if old client is older than 60 s #1226
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on ramosbugs/openidconnect-rs#152 and some discussions with @partim , it seems like the OpenID connect client does not automatically rediscover anything, leading to login loops when e.g. the JWKs are rolled (as the signature can no longer be verified).
This PR adds an explicit lifetime to the connection, and if the connection has existed for more than 60 seconds, it will initialise a new client. This is a tradeoff between doing rediscovery on every request (so requesting the /.well-known/openid-configuration endpoint, the jwk_uri inside that, and then the endpoint for the userinfo), which might slow things down on grouped requests, whilst also reasonably quickly learning about configuration changes.
The 60 seconds is arbitrary, and it might be nicer to make this configurable or document it somehow. Even nicer would be to honour the cache lifetimes of the HTTP responses, but I am not sure whether that is worth the effort.