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 (in uat/prod)SameSite: Strict — CSRF protection (set via Set-Cookie header)Path: /api/oidc/ — scoped to OIDC endpoints onlyMax-Age — set to the refresh token lifetime| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COOKIE_PATH
The cookie path, scoped to OIDC endpoints only.
|
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
with the SameSite=Strict attribute. |
static void |
clearRefreshTokenCookie(WebClient client)
Clears the refresh token cookie by setting its max-age to zero.
|
static java.lang.String |
getRefreshTokenCookie(WebClient client)
Reads the refresh token from the request cookie.
|
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.
|
public static final java.lang.String COOKIE_REFRESH_TOKEN
public static final java.lang.String COOKIE_PATH
public static final int DEFAULT_REFRESH_TOKEN_MAX_AGE
public static void setRefreshTokenCookie(@Nonnull
WebClient client,
@Nonnull
java.lang.String refreshToken)
The cookie is configured with HttpOnly, Secure (when
the request is over HTTPS), and scoped to the OIDC endpoint path.
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 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 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
with the SameSite=Strict attribute.
The standard javax.servlet.http.Cookie API does not support the
SameSite attribute. This method returns the complete header value
that can be added to the response via
response.addHeader("Set-Cookie", value).
refreshToken - the refresh token valuesecure - whether to include the Secure flagmaxAgeSeconds - the cookie lifetime in secondsstSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.