Class OidcToken
java.lang.Object
cloud.opencode.base.oauth2.oidc.OidcToken
OpenID Connect Token
OpenID Connect 令牌
Wraps an OAuth2 token with parsed ID token claims.
包装带有已解析 ID Token 声明的 OAuth2 令牌。
Features | 主要功能:
- Access to parsed ID token claims - 访问已解析的 ID Token 声明
- User identity information - 用户身份信息
- Token validation status - Token 验证状态
Usage Examples | 使用示例:
// Create from OAuth2 token
OidcToken oidcToken = OidcToken.from(oauth2Token);
// Access claims
String subject = oidcToken.subject();
String email = oidcToken.email();
String name = oidcToken.name();
// Check validation
if (oidcToken.isValid()) {
// Token is valid
}
Thread Safety | 线程安全:
This class is immutable and thread-safe.
此类是不可变的,线程安全。
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOidcToken(OAuth2Token oauth2Token, JwtClaims idTokenClaims) Create an OIDC token 创建 OIDC 令牌 -
Method Summary
Modifier and TypeMethodDescriptionGet the access token 获取访问令牌audience()Get the audience 获取受众email()Get the email claim 获取电子邮件声明booleanGet the expiration time 获取过期时间static OidcTokenfrom(OAuth2Token oauth2Token) Create from OAuth2 token by parsing the ID token 通过解析 ID Token 从 OAuth2 令牌创建inthashCode()booleanCheck if ID token is present 检查是否存在 ID TokenbooleanCheck if token has refresh token 检查令牌是否有刷新令牌idToken()Get the raw ID token string 获取原始 ID Token 字符串Get the parsed ID token claims 获取已解析的 ID Token 声明booleanCheck if email is verified 检查电子邮件是否已验证booleanCheck if token is expired 检查令牌是否已过期booleanisExpiringSoon(Duration threshold) Check if token is expiring soon 检查令牌是否即将过期booleanCheck if the ID token is expired 检查 ID Token 是否已过期issuedAt()Get the issued at time 获取发行时间issuer()Get the issuer 获取发行者booleanisValid()Check if the ID token is currently valid 检查 ID Token 当前是否有效name()Get the name claim 获取名称声明nonce()Get the nonce 获取 nonceGet the underlying OAuth2 token 获取底层 OAuth2 令牌picture()Get the picture URL claim 获取头像 URL 声明Get the refresh token 获取刷新令牌scopes()Get the scopes 获取范围subject()Get the subject (user ID) 获取主题(用户 ID)Get the Bearer authorization header 获取 Bearer 授权头toString()
-
Constructor Details
-
OidcToken
Create an OIDC token 创建 OIDC 令牌- Parameters:
oauth2Token- the OAuth2 token | OAuth2 令牌idTokenClaims- the parsed ID token claims | 已解析的 ID Token 声明
-
-
Method Details
-
from
Create from OAuth2 token by parsing the ID token 通过解析 ID Token 从 OAuth2 令牌创建- Parameters:
oauth2Token- the OAuth2 token | OAuth2 令牌- Returns:
- the OIDC token | OIDC 令牌
-
oauth2Token
Get the underlying OAuth2 token 获取底层 OAuth2 令牌- Returns:
- the OAuth2 token | OAuth2 令牌
-
idTokenClaims
-
hasIdToken
public boolean hasIdToken()Check if ID token is present 检查是否存在 ID Token- Returns:
- true if ID token exists | 如果存在 ID Token 返回 true
-
accessToken
-
refreshToken
-
idToken
Get the raw ID token string 获取原始 ID Token 字符串- Returns:
- the ID token string | ID Token 字符串
-
isExpired
public boolean isExpired()Check if token is expired 检查令牌是否已过期- Returns:
- true if expired | 如果已过期返回 true
-
isExpiringSoon
Check if token is expiring soon 检查令牌是否即将过期- Parameters:
threshold- the time threshold | 时间阈值- Returns:
- true if expiring within threshold | 如果在阈值内即将过期返回 true
-
hasRefreshToken
public boolean hasRefreshToken()Check if token has refresh token 检查令牌是否有刷新令牌- Returns:
- true if has refresh token | 如果有刷新令牌返回 true
-
toBearerHeader
Get the Bearer authorization header 获取 Bearer 授权头- Returns:
- the header value | 头值
-
subject
-
issuer
-
audience
-
expiration
-
issuedAt
-
nonce
-
email
-
isEmailVerified
public boolean isEmailVerified()Check if email is verified 检查电子邮件是否已验证- Returns:
- true if verified | 如果已验证返回 true
-
name
-
picture
-
isValid
public boolean isValid()Check if the ID token is currently valid 检查 ID Token 当前是否有效- Returns:
- true if valid | 如果有效返回 true
-
isIdTokenExpired
public boolean isIdTokenExpired()Check if the ID token is expired 检查 ID Token 是否已过期- Returns:
- true if expired | 如果已过期返回 true
-
scopes
-
equals
-
hashCode
-
toString
-