You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not reuse the same refresh token multiple times
- The "add a UAA token to HTTP request headers" flow works like this:
- User makes a request using AbstractReactorOperations -> Operator
- This adds an "Authorization" header, using Provider#getToken mono ;
if a value is cached it uses that, otherwise it uses whatever flow
is available to request a token.
- If the response is unauthorized, it means the access token is
expired, and the Operator calls Provider#invalidate ; and then
retries the request, which will trigger another #getToken call.
- There was a race condition, when an access_token was cached and
multiple request used it concurrently, they would all call
AbstractUaaTokenProvider#invalidate, and all reuse the same refresh
token. This is an issue when the UAA is configured with non-reusable
refresh tokens (revocable + rotating or unique), only the first
refresh token request succeeds, and all other refresh token requests
fail.
- This PR addresses this by ensuring that the cached refresh token is
removed from the cache right before being used. Any other call to
#invalidate will be a no-op.
- This is NOT a perfect fix, and there are some smaller scale race
conditions happening. For example, #invalidate calls
refreshTokens.remove and accessTokens.put sequentially. It is possible
that a concurrent request calls invalidate, finds the refreshTokens
cache empty, and then will populate accessTokens through #getToken ;
in that case there could be a race condition and two tokens fetched.
- Re-architecting the whole token logic is too big of a lift for the
project, so we accept that this solution is not perfect - as long as
the issues are recoverable.
- Fixes#1146
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
Copy file name to clipboardExpand all lines: cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/tokenprovider/AbstractUaaTokenProvider.java
+38-26Lines changed: 38 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ public abstract class AbstractUaaTokenProvider implements TokenProvider {
0 commit comments