app_user 短期令牌签发:开发者服务端以 App 键双头换发终端令牌(x-tansr-app-token 载体);鉴权复用 authenticateApp 全链(scope / status / 过期 / IP 白名单 / 签名 / license);endUserId 可打印 ASCII 1–128,ttlSeconds 60–86400 缺省 3600;令牌仅一次性回体、恒不入日志;令牌铸造径只读判限(并发 ≥ 硬帽 429 plan_concurrency_exceeded 不占位;test 档月度不同终端用户 SET > 100 → 429 plan_end_users_exceeded,shadow 下只计量)
const url = 'https://api.tansr.com/v1/app-tokens';const options = { method: 'POST', headers: { 'x-tansr-key-id': '<x-tansr-key-id>', 'x-tansr-key': '<x-tansr-key>', 'Content-Type': 'application/json' }, body: '{"endUserId":"example","ttlSeconds":1}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.tansr.com/v1/app-tokens \ --header 'Content-Type: application/json' \ --header 'x-tansr-key: <x-tansr-key>' \ --header 'x-tansr-key-id: <x-tansr-key-id>' \ --data '{ "endUserId": "example", "ttlSeconds": 1 }'Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”签名时间戳(unix 秒,十进制串;T-A34):与服务器时钟偏差 >300s → 401 signature_invalid
签名随机数(≥16 字符;T-A34):同 keyId 600s 窗内重现 → 401 nonce_replayed
请求签名(hex 小写;T-A34):HMAC-SHA256(K=sha256(SK 明文) 原始摘要, TWP1-HMAC-SHA256\n{METHOD}\n{path+query}\n{ts}\n{nonce}\n{sha256hex(rawBody)});三头须同现,在场恒校验;app signRequired 或 TANSR_API_TWP_REQUIRE_SIGNATURE=1 时未签名恒 401 signature_invalid
Request Bodyrequired
Section titled “Request Bodyrequired”object
Examplegenerated
{ "endUserId": "example", "ttlSeconds": 1}Responses
Section titled “Responses”{token, expiresAt, appId, endUserId}
object
Examplegenerated
{ "token": "example", "expiresAt": "example", "appId": "example", "endUserId": "example"}Bad_request(endUserId / ttlSeconds 形制)
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}App_key_invalid / signature_invalid / nonce_replayed
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}App_disabled / app_ip_denied / license_required
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}Plan_concurrency_exceeded(enforce)/ plan_end_users_exceeded(test 档 100;detail.limit/used)/ rate_limited
object
object
错误码注册表单源派生(src/http/errors.ts ERROR_CODES;码稳定,消费方按码翻译)
object
Example
{ "error": { "code": "adjudicator_not_authorized" }}本文是否有帮助?
感谢反馈,我们会持续改进这篇文章。