Skip to content

鉴权

第三方客户端必须先完成鉴权,才能接收事件。

消息顺序

校验 SERVER_HELLO 后,客户端发送的第一条 JSON 消息必须是 AUTH

SERVER_HELLO

方向:服务端到客户端。

WebSocket 连接建立后立即发送。

字段类型必填说明
typestring固定为 SERVER_HELLO
productstring固定为 tiktok_live_studio
channelstring固定为 third-party-im
versionstring服务端协议版本
json
{
  "type": "SERVER_HELLO",
  "product": "tiktok_live_studio",
  "channel": "third-party-im",
  "version": "1.0.0"
}

AUTH

方向:客户端到服务端。

必须是客户端发出的第一条 JSON 消息。

字段类型必填说明
typestring固定为 AUTH
app_idstring发放的应用标识
key_idstring发放的密钥版本标识
secretstring原始应用 secret
versionstring客户端协议版本
json
{
  "type": "AUTH",
  "app_id": "your_app_id",
  "key_id": "your_key_id",
  "secret": "your_secret",
  "version": "1.0.0"
}

警告

发送原始 secret。不要在客户端侧做哈希或变换。

AUTH_RESULT

方向:服务端到客户端。

鉴权成功或失败后发送。

字段类型必填说明
typestring固定为 AUTH_RESULT
successboolean鉴权是否成功
app_idstring从请求解析出的应用标识
app_namestring应用展示名称(如有)
messagestring可读结果说明
server_timenumberUnix 时间戳,毫秒
versionstring服务端协议版本
error_codestring鉴权失败时出现

成功:

json
{
  "type": "AUTH_RESULT",
  "success": true,
  "app_id": "your_app_id",
  "app_name": "Example App",
  "message": "Authentication successful",
  "server_time": 1786010400000,
  "version": "1.0.0"
}

失败:

json
{
  "type": "AUTH_RESULT",
  "success": false,
  "app_id": "your_app_id",
  "message": "Invalid credentials",
  "server_time": 1786010400000,
  "version": "1.0.0",
  "error_code": "INVALID_CREDENTIALS"
}

策略检查

鉴权只有在以下检查全部通过时才会成功:

  • 本地数据开放已开启。
  • app_id 存在于白名单中。
  • key_id 与配置的密钥匹配。
  • secret 与发放的凭证匹配。
  • 总连接数低于策略上限。
  • 单应用连接数低于策略上限。