public final class OidcCookieUtil
extends java.lang.Object
Only the refresh token is stored in an HttpOnly cookie. Access and ID tokens are returned to the frontend in the response body.
Cookie attributes:
HttpOnly: true — prevents JavaScript accessSecure: true — HTTPS only (required with SameSite=None)SameSite: None on HTTPS — allow credentialed cross-site calls
(via HttpClient.putCookie(Cookie, CookieSameSite))Path: / — forced by HttpClient.putCookie(Cookie, CookieSameSite)Max-Age — set to the refresh token lifetime| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COOKIE_PATH
Cookie path constant for tests/docs.
|
static java.lang.String |
COOKIE_REFRESH_TOKEN
The cookie name used to store the refresh token.
|
static int |
DEFAULT_REFRESH_TOKEN_MAX_AGE
Default refresh token lifetime: 30 days in seconds.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
buildSameSiteCookieHeader(java.lang.String refreshToken,
boolean secure,
int maxAgeSeconds)
Builds the
Set-Cookie header value for the refresh token cookie
(test / documentation helper). |
static java.lang.String |
buildSameSiteCookieHeader(java.lang.String cookieName,
java.lang.String cookieValue,
boolean secure,
int maxAgeSeconds)
Builds a complete
Set-Cookie header for any OIDC cookie name. |
static void |
clearRefreshTokenCookie(WebClient client)
Clears the refresh token cookie by setting its max-age to zero.
|
static void |
clearSessionTokenCookie(WebClient client)
Clears the one-time session key cookie set by
GET /oidc/callback. |
static java.lang.String |
getRefreshTokenCookie(WebClient client)
Reads the refresh token from the request cookie.
|
static void |
setRefreshTokenCookie(WebClient client,
OidcTokenResponse tokenResponse,
RestDefinition restDefinition)
Sets the refresh-token cookie using
OidcConfig.getRefreshCookieMaxAgeResolver(). |
static void |
setRefreshTokenCookie(WebClient client,
java.lang.String refreshToken)
Sets a secure, HttpOnly cookie containing the refresh token.
|
static void |
setRefreshTokenCookie(WebClient client,
java.lang.String refreshToken,
int maxAgeSeconds)
Sets a secure, HttpOnly cookie containing the refresh token with a
specified max-age.
|
static void |
setSessionTokenCookie(WebClient client,
java.lang.String sessionKey,
int maxAgeSeconds)
Sets the short-lived one-time session token cookie used by
GET /oidc/callback. |
public static final java.lang.String COOKIE_REFRESH_TOKEN
public static final java.lang.String COOKIE_PATH
/
by HttpClient.putCookie(Cookie, CookieSameSite).public static final int DEFAULT_REFRESH_TOKEN_MAX_AGE
public static void setRefreshTokenCookie(@Nonnull
WebClient client,
@Nonnull
java.lang.String refreshToken)
client - the WebClient for the current requestrefreshToken - the refresh token value to storepublic static void setRefreshTokenCookie(@Nonnull
WebClient client,
@Nonnull
java.lang.String refreshToken,
int maxAgeSeconds)
client - the WebClient for the current requestrefreshToken - the refresh token value to storemaxAgeSeconds - the cookie lifetime in secondspublic static void setRefreshTokenCookie(@Nonnull
WebClient client,
@Nonnull
OidcTokenResponse tokenResponse,
@Nonnull
RestDefinition restDefinition)
OidcConfig.getRefreshCookieMaxAgeResolver().client - the WebClient for the current requesttokenResponse - Cognito token response (must include a refresh token)restDefinition - the REST route handling this login or refreshpublic static void setSessionTokenCookie(@Nonnull
WebClient client,
@Nonnull
java.lang.String sessionKey,
int maxAgeSeconds)
GET /oidc/callback.client - the WebClient for the current requestsessionKey - the cache key for access/ID tokensmaxAgeSeconds - cookie lifetime in seconds@CheckReturnValue
@Nullable
public static java.lang.String getRefreshTokenCookie(@Nonnull
WebClient client)
client - the WebClient for the current requestnull if the cookie is not present or blankpublic static void clearRefreshTokenCookie(@Nonnull
WebClient client)
Used during logout to remove the refresh token from the browser.
client - the WebClient for the current requestpublic static void clearSessionTokenCookie(@Nonnull
WebClient client)
GET /oidc/callback.client - the WebClient for the current request@CheckReturnValue
@Nonnull
public static java.lang.String buildSameSiteCookieHeader(@Nonnull
java.lang.String refreshToken,
boolean secure,
int maxAgeSeconds)
Set-Cookie header value for the refresh token cookie
(test / documentation helper). Prefers HttpClient.putCookie(Cookie, CookieSameSite)
at runtime.
When secure is true, emits SameSite=None; Secure.
Without Secure, browsers reject SameSite=None, so HTTP uses SameSite=Lax.
refreshToken - the refresh token valuesecure - whether to include the Secure flag (and SameSite=None)maxAgeSeconds - the cookie lifetime in seconds@CheckReturnValue
@Nonnull
public static java.lang.String buildSameSiteCookieHeader(@Nonnull
java.lang.String cookieName,
@Nonnull
java.lang.String cookieValue,
boolean secure,
int maxAgeSeconds)
Set-Cookie header for any OIDC cookie name.cookieName - cookie namecookieValue - cookie valuesecure - whether the request is HTTPSmaxAgeSeconds - cookie lifetime in secondsstSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.