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 TypeMethodDescriptionGet the authorization endpoint URL 获取授权端点 URLGet the default scopes for this provider 获取此提供者的默认权限范围default StringGet the device authorization endpoint URL 获取设备授权端点 URLname()Get the provider name 获取提供者名称default booleanCheck if PKCE is required for this provider 检查此提供者是否需要 PKCEdefault StringGet the revocation endpoint URL 获取撤销端点 URLdefault booleanCheck if this provider supports device code flow 检查此提供者是否支持设备码流程default OAuth2ConfigConvert this provider to an OAuth2Config 将此提供者转换为 OAuth2Configdefault OAuth2ConfigConvert this provider to an OAuth2Config with additional scopes 将此提供者转换为带有额外权限范围的 OAuth2Configdefault OAuth2ConfigtoConfig(String clientId, String clientSecret, String redirectUri, Set<String> additionalScopes, GrantType grantType) Convert this provider to an OAuth2Config with custom settings 将此提供者转换为带有自定义设置的 OAuth2ConfigGet the token endpoint URL 获取令牌端点 URLdefault StringGet the user info endpoint URL 获取用户信息端点 URL
-
Method Details
-
name
-
authorizationEndpoint
String authorizationEndpoint()Get the authorization endpoint URL 获取授权端点 URL- Returns:
- the authorization endpoint | 授权端点
-
tokenEndpoint
-
userInfoEndpoint
Get the user info endpoint URL 获取用户信息端点 URL- Returns:
- the user info endpoint, or null if not supported | 用户信息端点,不支持则返回 null
-
revocationEndpoint
Get the revocation endpoint URL 获取撤销端点 URL- Returns:
- the revocation endpoint, or null if not supported | 撤销端点,不支持则返回 null
-
deviceAuthorizationEndpoint
Get the device authorization endpoint URL 获取设备授权端点 URL- Returns:
- the device authorization endpoint, or null if not supported | 设备授权端点,不支持则返回 null
-
defaultScopes
-
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
Convert this provider to an OAuth2Config 将此提供者转换为 OAuth2Config- Parameters:
clientId- the client ID | 客户端 IDclientSecret- 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 | 客户端 IDclientSecret- the client secret | 客户端密钥redirectUri- the redirect URI | 重定向 URIadditionalScopes- 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 | 客户端 IDclientSecret- the client secret | 客户端密钥redirectUri- the redirect URI | 重定向 URIadditionalScopes- additional scopes | 额外权限范围grantType- the grant type | 授权类型- Returns:
- the OAuth2Config | OAuth2 配置
-