OAuthTokenRequest

@Serializable
data class OAuthTokenRequest(val grantType: String = "authorization_code", val clientSecret: String, val code: String, val redirectUri: String, val clientId: String, val codeVerifier: String? = null)

OAuth 令牌请求 用于 OAuth 令牌交换接口的请求体(OAuth 流程)

官方文档:vds-docs/VDS 账户/VDS 账户快速接入(OAuth).md

请求参数说明:

  • grant_type: 授权类型

  • "authorization_code": 使用授权码交换令牌(初次授权)

  • "refresh_token": 使用刷新令牌获取新令牌(令牌刷新)

  • client_id: 应用 ID(格式 vap_xxxx)

  • client_secret: 应用密钥(开放平台签名,用于验证应用身份)

  • code: 授权码(从 OAuth 授权回调中获取,仅在 grant_type=authorization_code 时使用)

  • redirect_uri: 重定向 URI(必须与授权时使用的 URI 一致)

  • code_verifier: PKCE code_verifier(可选,启用 PKCE 时必需)

使用示例:

// 初次授权码交换
val tokenRequest = OAuthTokenRequest(
clientId = "vap_xxxxx",
clientSecret = sdkConfig.apiKey,
code = "auth_code_from_callback",
redirectUri = "http://localhost:8080/callback",
codeVerifier = "generated_code_verifier"
)

// 刷新令牌(通过 exchangeOAuthToken 方法)
val refreshRequest = OAuthTokenRequest(
grantType = "refresh_token",
clientId = "vap_xxxxx",
clientSecret = sdkConfig.apiKey,
code = "", // 不需要
redirectUri = "http://localhost:8080/callback"
)

Constructors

Link copied to clipboard
constructor(grantType: String = "authorization_code", clientSecret: String, code: String, redirectUri: String, clientId: String, codeVerifier: String? = null)

Properties

Link copied to clipboard
@SerialName(value = "client_id")
val clientId: String

应用 ID(格式 vap_xxxx)

Link copied to clipboard
@SerialName(value = "client_secret")
val clientSecret: String

应用密钥(开放平台签名)

Link copied to clipboard
@SerialName(value = "code")
val code: String

授权码(从 OAuth 授权回调中获取)

Link copied to clipboard
@SerialName(value = "code_verifier")
val codeVerifier: String? = null

可选的 PKCE code_verifier

Link copied to clipboard
@SerialName(value = "grant_type")
val grantType: String

授权类型,默认为 "authorization_code"

Link copied to clipboard
@SerialName(value = "redirect_uri")
val redirectUri: String

重定向 URI(必须与授权时一致)