Record Class DiscoveryDocument

java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.discovery.DiscoveryDocument

public record DiscoveryDocument(String issuer, String authorizationEndpoint, String tokenEndpoint, String userinfoEndpoint, String jwksUri, String registrationEndpoint, String revocationEndpoint, String introspectionEndpoint, String deviceAuthorizationEndpoint, String parEndpoint, List<String> scopesSupported, List<String> responseTypesSupported, List<String> grantTypesSupported, List<String> tokenEndpointAuthMethodsSupported, List<String> codeChallengeMethodsSupported) extends Record
OIDC Discovery Document OIDC 发现文档

Immutable record representing an OpenID Connect Discovery 1.0 configuration document as defined in the OIDC Discovery specification.

表示 OpenID Connect Discovery 1.0 配置文档的不可变记录, 按照 OIDC 发现规范定义。

Features | 主要功能:

  • All standard OIDC discovery fields - 所有标准 OIDC 发现字段
  • Builder pattern for construction - 构建器模式用于构建
  • Conversion to OAuth2Config - 转换为 OAuth2Config
  • Capability query methods - 能力查询方法

Usage Examples | 使用示例:

// Build a discovery document
DiscoveryDocument doc = DiscoveryDocument.builder()
    .issuer("https://accounts.example.com")
    .authorizationEndpoint("https://accounts.example.com/authorize")
    .tokenEndpoint("https://accounts.example.com/token")
    .build();

// Check capabilities
boolean supportsPkce = doc.supportsPkce();
boolean supportsRefresh = doc.supports("refresh_token");

// Convert to OAuth2Config
OAuth2Config config = doc.toConfig("client-id", "client-secret");

Thread Safety | 线程安全:

This class is immutable and thread-safe. All list fields are unmodifiable.

此类是不可变的,线程安全。所有列表字段都是不可修改的。

Since:
JDK 25, opencode-base-oauth2 V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DiscoveryDocument

      public DiscoveryDocument(String issuer, String authorizationEndpoint, String tokenEndpoint, String userinfoEndpoint, String jwksUri, String registrationEndpoint, String revocationEndpoint, String introspectionEndpoint, String deviceAuthorizationEndpoint, String parEndpoint, List<String> scopesSupported, List<String> responseTypesSupported, List<String> grantTypesSupported, List<String> tokenEndpointAuthMethodsSupported, List<String> codeChallengeMethodsSupported)
      Compact constructor with defensive copying and validation. 带防御性复制和验证的紧凑构造器。
  • Method Details

    • toConfig

      public OAuth2Config toConfig(String clientId, String clientSecret)
      Convert this discovery document to an OAuth2Config using the given client credentials. 使用给定的客户端凭证将此发现文档转换为 OAuth2Config。
      Parameters:
      clientId - the client ID | 客户端 ID
      clientSecret - the client secret (may be null for public clients) | 客户端密钥(公共客户端可为 null)
      Returns:
      the OAuth2Config built from this discovery document | 从此发现文档构建的 OAuth2Config
      Throws:
      NullPointerException - if clientId is null | 如果 clientId 为 null
    • supports

      public boolean supports(String grantType)
      Check if the authorization server supports the given grant type. 检查授权服务器是否支持给定的授权类型。
      Parameters:
      grantType - the grant type to check (e.g., "authorization_code", "refresh_token") | 要检查的授权类型(例如 "authorization_code"、"refresh_token")
      Returns:
      true if the grant type is supported | 如果支持该授权类型返回 true
    • supportsScope

      public boolean supportsScope(String scope)
      Check if the authorization server supports the given scope. 检查授权服务器是否支持给定的权限范围。
      Parameters:
      scope - the scope to check (e.g., "openid", "email") | 要检查的权限范围(例如 "openid"、"email")
      Returns:
      true if the scope is supported | 如果支持该权限范围返回 true
    • supportsPkce

      public boolean supportsPkce()
      Check if the authorization server supports PKCE (S256 code challenge method). 检查授权服务器是否支持 PKCE(S256 代码挑战方法)。
      Returns:
      true if PKCE with S256 is supported | 如果支持 S256 的 PKCE 返回 true
    • builder

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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • issuer

      public String issuer()
      Returns the value of the issuer record component.
      Returns:
      the value of the issuer 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
    • jwksUri

      public String jwksUri()
      Returns the value of the jwksUri record component.
      Returns:
      the value of the jwksUri record component
    • registrationEndpoint

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

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

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

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

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

      public List<String> scopesSupported()
      Returns the value of the scopesSupported record component.
      Returns:
      the value of the scopesSupported record component
    • responseTypesSupported

      public List<String> responseTypesSupported()
      Returns the value of the responseTypesSupported record component.
      Returns:
      the value of the responseTypesSupported record component
    • grantTypesSupported

      public List<String> grantTypesSupported()
      Returns the value of the grantTypesSupported record component.
      Returns:
      the value of the grantTypesSupported record component
    • tokenEndpointAuthMethodsSupported

      public List<String> tokenEndpointAuthMethodsSupported()
      Returns the value of the tokenEndpointAuthMethodsSupported record component.
      Returns:
      the value of the tokenEndpointAuthMethodsSupported record component
    • codeChallengeMethodsSupported

      public List<String> codeChallengeMethodsSupported()
      Returns the value of the codeChallengeMethodsSupported record component.
      Returns:
      the value of the codeChallengeMethodsSupported record component