Interface OAuth2Provider

All Known Implementing Classes:
CustomProvider

public interface OAuth2Provider
OAuth2 Provider Interface OAuth2 Provider 接口

Defines the contract for OAuth2 identity providers.

定义 OAuth2 身份提供者的契约。

Features | 主要功能:

  • Endpoint configuration - 端点配置
  • Default scopes - 默认权限范围
  • Config builder integration - 配置构建器集成

Usage Examples | 使用示例:

// Use built-in provider
OAuth2Client client = OAuth2Client.builder()
    .provider(Providers.GOOGLE)
    .clientId("your-client-id")
    .clientSecret("your-client-secret")
    .build();

// Create custom provider
OAuth2Provider myProvider = new OAuth2Provider() {
    @Override
    public String name() { return "MyProvider"; }
    @Override
    public String authorizationEndpoint() { return "https://..."; }
    // ... other methods
};

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the authorization endpoint URL 获取授权端点 URL
    default Set<String>
    Get the default scopes for this provider 获取此提供者的默认权限范围
    default String
    Get the device authorization endpoint URL 获取设备授权端点 URL
    Get the provider name 获取提供者名称
    default boolean
    Check if PKCE is required for this provider 检查此提供者是否需要 PKCE
    default String
    Get the revocation endpoint URL 获取撤销端点 URL
    default boolean
    Check if this provider supports device code flow 检查此提供者是否支持设备码流程
    default OAuth2Config
    toConfig(String clientId, String clientSecret, String redirectUri)
    Convert this provider to an OAuth2Config 将此提供者转换为 OAuth2Config
    default OAuth2Config
    toConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes)
    Convert this provider to an OAuth2Config with additional scopes 将此提供者转换为带有额外权限范围的 OAuth2Config
    default OAuth2Config
    toConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes, GrantType grantType)
    Convert this provider to an OAuth2Config with custom settings 将此提供者转换为带有自定义设置的 OAuth2Config
    Get the token endpoint URL 获取令牌端点 URL
    default String
    Get the user info endpoint URL 获取用户信息端点 URL
  • Method Details

    • name

      String name()
      Get the provider name 获取提供者名称
      Returns:
      the provider name | 提供者名称
    • authorizationEndpoint

      String authorizationEndpoint()
      Get the authorization endpoint URL 获取授权端点 URL
      Returns:
      the authorization endpoint | 授权端点
    • tokenEndpoint

      String tokenEndpoint()
      Get the token endpoint URL 获取令牌端点 URL
      Returns:
      the token endpoint | 令牌端点
    • userInfoEndpoint

      default String userInfoEndpoint()
      Get the user info endpoint URL 获取用户信息端点 URL
      Returns:
      the user info endpoint, or null if not supported | 用户信息端点,不支持则返回 null
    • revocationEndpoint

      default String revocationEndpoint()
      Get the revocation endpoint URL 获取撤销端点 URL
      Returns:
      the revocation endpoint, or null if not supported | 撤销端点,不支持则返回 null
    • deviceAuthorizationEndpoint

      default String deviceAuthorizationEndpoint()
      Get the device authorization endpoint URL 获取设备授权端点 URL
      Returns:
      the device authorization endpoint, or null if not supported | 设备授权端点,不支持则返回 null
    • defaultScopes

      default Set<String> defaultScopes()
      Get the default scopes for this provider 获取此提供者的默认权限范围
      Returns:
      the default scopes | 默认权限范围
    • requiresPkce

      default boolean requiresPkce()
      Check if PKCE is required for this provider 检查此提供者是否需要 PKCE
      Returns:
      true if PKCE is required | 需要 PKCE 返回 true
    • supportsDeviceCode

      default boolean supportsDeviceCode()
      Check if this provider supports device code flow 检查此提供者是否支持设备码流程
      Returns:
      true if device code is supported | 支持设备码返回 true
    • toConfig

      default OAuth2Config toConfig(String clientId, String clientSecret, String redirectUri)
      Convert this provider to an OAuth2Config 将此提供者转换为 OAuth2Config
      Parameters:
      clientId - the client ID | 客户端 ID
      clientSecret - the client secret | 客户端密钥
      redirectUri - the redirect URI | 重定向 URI
      Returns:
      the OAuth2Config | OAuth2 配置
    • toConfig

      default OAuth2Config toConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes)
      Convert this provider to an OAuth2Config with additional scopes 将此提供者转换为带有额外权限范围的 OAuth2Config
      Parameters:
      clientId - the client ID | 客户端 ID
      clientSecret - the client secret | 客户端密钥
      redirectUri - the redirect URI | 重定向 URI
      additionalScopes - additional scopes | 额外权限范围
      Returns:
      the OAuth2Config | OAuth2 配置
    • toConfig

      default OAuth2Config toConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes, GrantType grantType)
      Convert this provider to an OAuth2Config with custom settings 将此提供者转换为带有自定义设置的 OAuth2Config
      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 配置