Class OidcToken

java.lang.Object
cloud.opencode.base.oauth2.oidc.OidcToken

public final class OidcToken extends Object
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 Details

    • OidcToken

      public OidcToken(OAuth2Token oauth2Token, JwtClaims idTokenClaims)
      Create an OIDC token 创建 OIDC 令牌
      Parameters:
      oauth2Token - the OAuth2 token | OAuth2 令牌
      idTokenClaims - the parsed ID token claims | 已解析的 ID Token 声明
  • Method Details

    • from

      public static OidcToken from(OAuth2Token oauth2Token)
      Create from OAuth2 token by parsing the ID token 通过解析 ID Token 从 OAuth2 令牌创建
      Parameters:
      oauth2Token - the OAuth2 token | OAuth2 令牌
      Returns:
      the OIDC token | OIDC 令牌
    • oauth2Token

      public OAuth2Token oauth2Token()
      Get the underlying OAuth2 token 获取底层 OAuth2 令牌
      Returns:
      the OAuth2 token | OAuth2 令牌
    • idTokenClaims

      public Optional<JwtClaims> idTokenClaims()
      Get the parsed ID token claims 获取已解析的 ID Token 声明
      Returns:
      the claims if available | 声明(如果可用)
    • hasIdToken

      public boolean hasIdToken()
      Check if ID token is present 检查是否存在 ID Token
      Returns:
      true if ID token exists | 如果存在 ID Token 返回 true
    • accessToken

      public String accessToken()
      Get the access token 获取访问令牌
      Returns:
      the access token | 访问令牌
    • refreshToken

      public String refreshToken()
      Get the refresh token 获取刷新令牌
      Returns:
      the refresh token | 刷新令牌
    • idToken

      public String 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

      public boolean isExpiringSoon(Duration threshold)
      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

      public String toBearerHeader()
      Get the Bearer authorization header 获取 Bearer 授权头
      Returns:
      the header value | 头值
    • subject

      public String subject()
      Get the subject (user ID) 获取主题(用户 ID)
      Returns:
      the subject | 主题
    • issuer

      public String issuer()
      Get the issuer 获取发行者
      Returns:
      the issuer | 发行者
    • audience

      public String audience()
      Get the audience 获取受众
      Returns:
      the audience | 受众
    • expiration

      public Instant expiration()
      Get the expiration time 获取过期时间
      Returns:
      the expiration time | 过期时间
    • issuedAt

      public Instant issuedAt()
      Get the issued at time 获取发行时间
      Returns:
      the issued at time | 发行时间
    • nonce

      public String nonce()
      Get the nonce 获取 nonce
      Returns:
      the nonce | nonce
    • email

      public String email()
      Get the email claim 获取电子邮件声明
      Returns:
      the email | 电子邮件
    • isEmailVerified

      public boolean isEmailVerified()
      Check if email is verified 检查电子邮件是否已验证
      Returns:
      true if verified | 如果已验证返回 true
    • name

      public String name()
      Get the name claim 获取名称声明
      Returns:
      the name | 名称
    • picture

      public String picture()
      Get the picture URL claim 获取头像 URL 声明
      Returns:
      the picture URL | 头像 URL
    • 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

      public Set<String> scopes()
      Get the scopes 获取范围
      Returns:
      the scopes | 范围
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object