Enum Class GrantType

java.lang.Object
java.lang.Enum<GrantType>
cloud.opencode.base.oauth2.grant.GrantType
All Implemented Interfaces:
Serializable, Comparable<GrantType>, Constable

public enum GrantType extends Enum<GrantType>
OAuth2 Grant Type Enum OAuth2 授权类型枚举

Defines the supported OAuth2 grant types.

定义支持的 OAuth2 授权类型。

Supported Grant Types | 支持的授权类型:

  • AUTHORIZATION_CODE - Web applications - Web 应用
  • CLIENT_CREDENTIALS - Server-to-server - 服务器间通信
  • DEVICE_CODE - CLI/IoT devices - CLI/IoT 设备
  • REFRESH_TOKEN - Token refresh - Token 刷新

Features | 主要功能:

  • OAuth2 grant type enumeration - OAuth2授权类型枚举
  • Supports authorization_code, client_credentials, device_code, refresh_token - 支持授权码、客户端凭证、设备码、刷新令牌

Usage Examples | 使用示例:

// Select grant type for OAuth2 flow
// 为OAuth2流程选择授权类型
GrantType type = GrantType.AUTHORIZATION_CODE;
String value = type.getValue();

Security | 安全性:

  • Thread-safe: Yes (immutable enum) - 线程安全: 是(不可变枚举)
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Enum Constant Details

    • AUTHORIZATION_CODE

      public static final GrantType AUTHORIZATION_CODE
      Authorization Code Grant 授权码模式

      Best for web applications with a backend server.

      最适合有后端服务器的 Web 应用。

    • CLIENT_CREDENTIALS

      public static final GrantType CLIENT_CREDENTIALS
      Client Credentials Grant 客户端凭证模式

      Best for server-to-server communication without user context.

      最适合无用户上下文的服务器间通信。

    • DEVICE_CODE

      public static final GrantType DEVICE_CODE
      Device Code Grant (RFC 8628) 设备码模式

      Best for devices with limited input capabilities (CLI, IoT, TV).

      最适合输入能力有限的设备(CLI、IoT、TV)。

    • REFRESH_TOKEN

      public static final GrantType REFRESH_TOKEN
      Refresh Token Grant 刷新令牌模式

      Used to obtain a new access token using a refresh token.

      用于使用刷新令牌获取新的访问令牌。

  • Method Details

    • values

      public static GrantType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static GrantType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • value

      public String value()
      Get the grant type value for OAuth2 requests 获取用于 OAuth2 请求的授权类型值
      Returns:
      the grant type value | 授权类型值
    • fromValue

      public static GrantType fromValue(String value)
      Parse grant type from string value 从字符串值解析授权类型
      Parameters:
      value - the string value | 字符串值
      Returns:
      the grant type | 授权类型
      Throws:
      IllegalArgumentException - if value is not recognized | 如果值无法识别
    • toString

      public String toString()
      Overrides:
      toString in class Enum<GrantType>