Record Class OAuth2Config

java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.OAuth2Config

public record OAuth2Config(String clientId, String clientSecret, String authorizationEndpoint, String tokenEndpoint, String userInfoEndpoint, String revocationEndpoint, String deviceAuthorizationEndpoint, String redirectUri, Set<String> scopes, GrantType grantType, boolean usePkce, Duration connectTimeout, Duration readTimeout, Duration refreshThreshold, String parEndpoint, String introspectionEndpoint, String resource, String expectedIssuer) extends Record
OAuth2 Configuration Record OAuth2 配置记录

Immutable configuration for OAuth2 client.

OAuth2 客户端的不可变配置。

Features | 主要功能:

  • Client credentials - 客户端凭证
  • Endpoint configuration - 端点配置
  • Scope management - 权限范围管理
  • PKCE settings - PKCE 设置
  • Timeout configuration - 超时配置
  • PAR endpoint (RFC 9126) - PAR 端点
  • Introspection endpoint (RFC 7662) - 内省端点
  • Resource indicator (RFC 8707) - 资源指示器
  • Issuer validation (RFC 9207) - 颁发者验证

Usage Examples | 使用示例:

// Build configuration
OAuth2Config config = OAuth2Config.builder()
    .clientId("your-client-id")
    .clientSecret("your-client-secret")
    .authorizationEndpoint("https://oauth.example.com/authorize")
    .tokenEndpoint("https://oauth.example.com/token")
    .redirectUri("https://yourapp.com/callback")
    .scopes("openid", "email", "profile")
    .parEndpoint("https://oauth.example.com/par")
    .introspectionEndpoint("https://oauth.example.com/introspect")
    .resource("https://api.example.com")
    .expectedIssuer("https://oauth.example.com")
    .build();

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

  • Method Details

    • toString

      public String toString()
      Returns a string representation with clientSecret redacted. 返回 clientSecret 已脱敏的字符串表示。
      Specified by:
      toString in class Record
    • isAuthorizationCodeFlow

      public boolean isAuthorizationCodeFlow()
      Check if this config is for authorization code flow 检查此配置是否用于授权码流程
      Returns:
      true if authorization code flow | 授权码流程返回 true
    • isClientCredentialsFlow

      public boolean isClientCredentialsFlow()
      Check if this config is for client credentials flow 检查此配置是否用于客户端凭证流程
      Returns:
      true if client credentials flow | 客户端凭证流程返回 true
    • isDeviceCodeFlow

      public boolean isDeviceCodeFlow()
      Check if this config is for device code flow 检查此配置是否用于设备码流程
      Returns:
      true if device code flow | 设备码流程返回 true
    • hasUserInfoEndpoint

      public boolean hasUserInfoEndpoint()
      Check if user info endpoint is configured 检查是否配置了用户信息端点
      Returns:
      true if configured | 已配置返回 true
    • hasRevocationEndpoint

      public boolean hasRevocationEndpoint()
      Check if revocation endpoint is configured 检查是否配置了撤销端点
      Returns:
      true if configured | 已配置返回 true
    • hasDeviceAuthorizationEndpoint

      public boolean hasDeviceAuthorizationEndpoint()
      Check if device authorization endpoint is configured 检查是否配置了设备授权端点
      Returns:
      true if configured | 已配置返回 true
    • hasParEndpoint

      public boolean hasParEndpoint()
      Check if PAR endpoint is configured (RFC 9126) 检查是否配置了 PAR 端点(RFC 9126)
      Returns:
      true if configured | 已配置返回 true
    • hasIntrospectionEndpoint

      public boolean hasIntrospectionEndpoint()
      Check if introspection endpoint is configured (RFC 7662) 检查是否配置了内省端点(RFC 7662)
      Returns:
      true if configured | 已配置返回 true
    • hasResource

      public boolean hasResource()
      Check if resource indicator is configured (RFC 8707) 检查是否配置了资源指示器(RFC 8707)
      Returns:
      true if configured | 已配置返回 true
    • hasExpectedIssuer

      public boolean hasExpectedIssuer()
      Check if expected issuer is configured for validation (RFC 9207) 检查是否配置了用于验证的预期颁发者(RFC 9207)
      Returns:
      true if configured | 已配置返回 true
    • builder

      public static OAuth2Config.Builder builder()
      Create a new builder 创建新的构建器
      Returns:
      the builder | 构建器
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • clientId

      public String clientId()
      Returns the value of the clientId record component.
      Returns:
      the value of the clientId record component
    • clientSecret

      public String clientSecret()
      Returns the value of the clientSecret record component.
      Returns:
      the value of the clientSecret record component
    • authorizationEndpoint

      public String authorizationEndpoint()
      Returns the value of the authorizationEndpoint record component.
      Returns:
      the value of the authorizationEndpoint record component
    • tokenEndpoint

      public String tokenEndpoint()
      Returns the value of the tokenEndpoint record component.
      Returns:
      the value of the tokenEndpoint record component
    • userInfoEndpoint

      public String userInfoEndpoint()
      Returns the value of the userInfoEndpoint record component.
      Returns:
      the value of the userInfoEndpoint record component
    • revocationEndpoint

      public String revocationEndpoint()
      Returns the value of the revocationEndpoint record component.
      Returns:
      the value of the revocationEndpoint record component
    • deviceAuthorizationEndpoint

      public String deviceAuthorizationEndpoint()
      Returns the value of the deviceAuthorizationEndpoint record component.
      Returns:
      the value of the deviceAuthorizationEndpoint record component
    • redirectUri

      public String redirectUri()
      Returns the value of the redirectUri record component.
      Returns:
      the value of the redirectUri record component
    • scopes

      public Set<String> scopes()
      Returns the value of the scopes record component.
      Returns:
      the value of the scopes record component
    • grantType

      public GrantType grantType()
      Returns the value of the grantType record component.
      Returns:
      the value of the grantType record component
    • usePkce

      public boolean usePkce()
      Returns the value of the usePkce record component.
      Returns:
      the value of the usePkce record component
    • connectTimeout

      public Duration connectTimeout()
      Returns the value of the connectTimeout record component.
      Returns:
      the value of the connectTimeout record component
    • readTimeout

      public Duration readTimeout()
      Returns the value of the readTimeout record component.
      Returns:
      the value of the readTimeout record component
    • refreshThreshold

      public Duration refreshThreshold()
      Returns the value of the refreshThreshold record component.
      Returns:
      the value of the refreshThreshold record component
    • parEndpoint

      public String parEndpoint()
      Returns the value of the parEndpoint record component.
      Returns:
      the value of the parEndpoint record component
    • introspectionEndpoint

      public String introspectionEndpoint()
      Returns the value of the introspectionEndpoint record component.
      Returns:
      the value of the introspectionEndpoint record component
    • resource

      public String resource()
      Returns the value of the resource record component.
      Returns:
      the value of the resource record component
    • expectedIssuer

      public String expectedIssuer()
      Returns the value of the expectedIssuer record component.
      Returns:
      the value of the expectedIssuer record component