Class CustomProvider

java.lang.Object
cloud.opencode.base.oauth2.provider.CustomProvider
All Implemented Interfaces:
OAuth2Provider

public final class CustomProvider extends Object implements OAuth2Provider
Custom OAuth2 Provider 自定义 OAuth2 Provider

A configurable OAuth2 provider for custom authorization servers.

用于自定义授权服务器的可配置 OAuth2 提供者。

Features | 主要功能:

  • Fully configurable endpoints - 完全可配置的端点
  • Custom default scopes - 自定义默认范围
  • Immutable after creation - 创建后不可变

Usage Examples | 使用示例:

// Create a custom provider
OAuth2Provider provider = CustomProvider.builder()
    .name("MyProvider")
    .authorizationEndpoint("https://auth.example.com/authorize")
    .tokenEndpoint("https://auth.example.com/token")
    .userInfoEndpoint("https://auth.example.com/userinfo")
    .defaultScopes("openid", "profile", "email")
    .build();

// Use the provider
OAuth2Client client = OAuth2Client.builder()
    .provider(provider)
    .clientId("my-client-id")
    .clientSecret("my-client-secret")
    .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:
  • Method Details

    • name

      public String name()
      Description copied from interface: OAuth2Provider
      Get the provider name 获取提供者名称
      Specified by:
      name in interface OAuth2Provider
      Returns:
      the provider name | 提供者名称
    • authorizationEndpoint

      public String authorizationEndpoint()
      Description copied from interface: OAuth2Provider
      Get the authorization endpoint URL 获取授权端点 URL
      Specified by:
      authorizationEndpoint in interface OAuth2Provider
      Returns:
      the authorization endpoint | 授权端点
    • tokenEndpoint

      public String tokenEndpoint()
      Description copied from interface: OAuth2Provider
      Get the token endpoint URL 获取令牌端点 URL
      Specified by:
      tokenEndpoint in interface OAuth2Provider
      Returns:
      the token endpoint | 令牌端点
    • userInfoEndpoint

      public String userInfoEndpoint()
      Description copied from interface: OAuth2Provider
      Get the user info endpoint URL 获取用户信息端点 URL
      Specified by:
      userInfoEndpoint in interface OAuth2Provider
      Returns:
      the user info endpoint, or null if not supported | 用户信息端点,不支持则返回 null
    • revocationEndpoint

      public String revocationEndpoint()
      Description copied from interface: OAuth2Provider
      Get the revocation endpoint URL 获取撤销端点 URL
      Specified by:
      revocationEndpoint in interface OAuth2Provider
      Returns:
      the revocation endpoint, or null if not supported | 撤销端点,不支持则返回 null
    • deviceAuthorizationEndpoint

      public String deviceAuthorizationEndpoint()
      Description copied from interface: OAuth2Provider
      Get the device authorization endpoint URL 获取设备授权端点 URL
      Specified by:
      deviceAuthorizationEndpoint in interface OAuth2Provider
      Returns:
      the device authorization endpoint, or null if not supported | 设备授权端点,不支持则返回 null
    • defaultScopes

      public Set<String> defaultScopes()
      Description copied from interface: OAuth2Provider
      Get the default scopes for this provider 获取此提供者的默认权限范围
      Specified by:
      defaultScopes in interface OAuth2Provider
      Returns:
      the default scopes | 默认权限范围
    • jwksUri

      public String jwksUri()
      Get the JWKS URI 获取 JWKS URI
      Returns:
      the JWKS URI | JWKS URI
    • issuer

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

      public OAuth2Config toConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes, GrantType grantType)
      Description copied from interface: OAuth2Provider
      Convert this provider to an OAuth2Config with custom settings 将此提供者转换为带有自定义设置的 OAuth2Config
      Specified by:
      toConfig in interface OAuth2Provider
      Parameters:
      clientId - the client ID | 客户端 ID
      clientSecret - the client secret | 客户端密钥
      redirectUri - the redirect URI | 重定向 URI
      additionalScopes - additional scopes | 额外权限范围
      grantType - the grant type | 授权类型
      Returns:
      the OAuth2Config | OAuth2 配置
    • builder

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

      public static CustomProvider.Builder from(OAuth2Provider provider)
      Create a builder from an existing provider 从现有 Provider 创建构建器
      Parameters:
      provider - the provider to copy | 要复制的 Provider
      Returns:
      the builder | 构建器
    • 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