TokenInfo

@Serializable
data class TokenInfo(val accessToken: String, val apiKey: String, val expiresAt: Long, val tokenType: String, val refreshToken: String? = null)

令牌信息 SDK 内部使用的令牌存储结构

用于统一管理签名交换和 OAuth 两种认证方式获取的令牌。

字段说明:

  • accessToken: 访问令牌,用于 Authorization: Bearer 认证头

  • 签名交换:从 /api/auth/token 接口获取

  • OAuth 流程:从 /api/proxy/account/sso/token 接口获取

  • apiKey: API 密钥,用于 X-Api-Key 认证头

  • 仅签名交换流程返回此字段

  • OAuth 流程此字段为空字符串

  • expiresAt: 过期时间戳(毫秒),用于判断令牌是否过期

  • 计算方式:当前时间 + expiresIn * 1000

  • tokenType: 令牌类型,通常为 "Bearer"

  • refreshToken: 可选的刷新令牌,用于 OAuth 令牌刷新

  • 仅 OAuth 流程返回此字段

  • 用于在 access_token 过期后获取新的访问令牌

刷新窗口说明:

  • 当剩余有效期 <= 300 秒(5 分钟)时,令牌被视为即将过期

  • 此时应调用刷新接口获取新令牌

  • 刷新窗口大小:REFRESH_WINDOW_MS = 300,000ms

使用示例:

val tokenInfo = authManager.exchangeToken(appId, appSecret)

// 检查是否过期
if (tokenInfo.isExpired()) {
// 需要刷新令牌
val newTokenInfo = authManager.refreshToken()
}

// 获取访问令牌
val accessToken = tokenInfo.accessToken

Constructors

Link copied to clipboard
constructor(accessToken: String, apiKey: String, expiresAt: Long, tokenType: String, refreshToken: String? = null)

Properties

Link copied to clipboard

访问令牌,用于 Authorization: Bearer 认证头

Link copied to clipboard

API 密钥,用于 X-Api-Key 认证头

Link copied to clipboard

过期时间戳(毫秒)

Link copied to clipboard
val refreshToken: String? = null

可选的刷新令牌,用于 OAuth 令牌刷新

Link copied to clipboard

令牌类型

Functions

Link copied to clipboard

检查是否需要刷新令牌 根据文档,当剩余有效期 <= 300 秒(5 分钟)时应该刷新