public class OauthTokenCache extends Object
OauthTokenCache is a simple OAuthBearerToken Cache.
Users can call isTokenExpired() method to check if cache is expired.
If the cache is expired then users can call setCurrentToken(OAuthBearerToken) to set a newly retrieved token.
calculateTokenRenRefreshTime() is the refresh algorithm to
calculate token expiry time at time of setting the token, using setCurrentToken(OAuthBearerToken). In order to encourage
fetching a new token in advance before the actual token expiration, calculateTokenRenRefreshTime() will try to return a cache expiration
time before the token expiration time.
| Modifier and Type | Field and Description |
|---|---|
static float |
CACHE_EXPIRY_THRESHOLD |
| Constructor and Description |
|---|
OauthTokenCache(short cacheExpiryBufferSeconds) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
calculateTokenExpiryTime(org.apache.kafka.common.security.oauthbearer.OAuthBearerToken currentToken) |
org.apache.kafka.common.security.oauthbearer.OAuthBearerToken |
getCurrentToken() |
boolean |
isTokenExpired()
This method can be used to decide whether we should a network call to OAuth/OIDC provider and
get a new token or use existing token in the cache.
|
void |
setCurrentToken(org.apache.kafka.common.security.oauthbearer.OAuthBearerToken currentToken)
This method can be used be to set token right after you fetch the token from the OAuth/OIDC
provider.
|
public static final float CACHE_EXPIRY_THRESHOLD
public org.apache.kafka.common.security.oauthbearer.OAuthBearerToken getCurrentToken()
public void setCurrentToken(org.apache.kafka.common.security.oauthbearer.OAuthBearerToken currentToken)
currentToken - is a newly fetched token from a OAuth/OIDC provider.protected long calculateTokenExpiryTime(org.apache.kafka.common.security.oauthbearer.OAuthBearerToken currentToken)
public boolean isTokenExpired()
setCurrentToken(OAuthBearerToken) to update
this cache with new token. if this method returns false, then we can use token present in this
cache itself.Copyright © 2025 Confluent, Inc.. All rights reserved.