public final class OidcTokenExchange
extends java.lang.Object
/oauth2/token endpoint
for exchanging authorisation codes and refreshing tokens.
All methods read configuration from OidcConfig and POST
form-encoded requests to the Cognito token endpoint.
| Modifier and Type | Field and Description |
|---|---|
static int |
REFRESH_COOLDOWN_SECONDS
Cooldown period in seconds — refresh tokens created within this window cannot be refreshed.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
clearAllCooldowns()
Clears all cooldown entries.
|
static void |
clearRefreshTokenCooldown(java.lang.String refreshToken)
Removes a refresh token from the cooldown cache.
|
static OidcTokenResponse |
exchangeAuthCode(java.lang.String code)
Exchanges an authorisation code for tokens using the
authorization_code grant type. |
static OidcTokenResponse |
parseTokenResponse(java.lang.String responseBody)
Parses a successful JSON response into an
OidcTokenResponse. |
static OidcTokenResponse |
postTokenRequest(java.lang.String tokenEndpoint,
java.lang.String formBody)
Posts a form-encoded request to the given token endpoint and parses
the JSON response.
|
static void |
recordRefreshTokenCreation(java.lang.String refreshToken)
Records that a refresh token has just been created or refreshed.
|
static OidcTokenResponse |
refreshTokens(java.lang.String refreshToken)
Exchanges a refresh token for new access and ID tokens using the
refresh_token grant type. |
public static final int REFRESH_COOLDOWN_SECONDS
@CheckReturnValue @Nonnull public static OidcTokenResponse exchangeAuthCode(@Nonnull java.lang.String code) throws OidcTokenExchangeException
authorization_code grant type.code - the authorisation code received from Cognito's callbackOidcTokenExchangeException - if Cognito returns an error or the request fails@CheckReturnValue @Nonnull public static OidcTokenResponse refreshTokens(@Nonnull java.lang.String refreshToken) throws OidcTokenExchangeException
refresh_token grant type.
Note: Cognito does not return a new refresh token in the response for refresh_token grants.
refreshToken - the refresh tokenOidcTokenExchangeException - if Cognito returns an error or the request fails@CheckReturnValue @Nonnull public static OidcTokenResponse postTokenRequest(@Nonnull java.lang.String tokenEndpoint, @Nonnull java.lang.String formBody) throws OidcTokenExchangeException
tokenEndpoint - the Cognito token endpoint URLformBody - the URL-encoded form bodyOidcTokenExchangeException - on HTTP or parsing errors@CheckReturnValue @Nonnull public static OidcTokenResponse parseTokenResponse(@Nonnull java.lang.String responseBody) throws OidcTokenExchangeException
OidcTokenResponse.OidcTokenExchangeExceptionpublic static void recordRefreshTokenCreation(@Nonnull
java.lang.String refreshToken)
refreshTokens(java.lang.String) within the cooldown period
will be rejected with a too_many_requests error.refreshToken - the refresh token to recordpublic static void clearRefreshTokenCooldown(@Nonnull
java.lang.String refreshToken)
refreshToken - the refresh token to removepublic static void clearAllCooldowns()
stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.