auth-http-api-cloudbase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to use this skill
何时使用该技能
Use this skill whenever you need to call CloudBase Auth via raw HTTP APIs, for example:
- Non-Node backends (Go, Python, Java, PHP, etc.)
- Integration tests or admin scripts that use curl or language HTTP clients
- Gateways or proxies that sit in front of CloudBase and manage tokens themselves
Do not use this skill for:
- Frontend Web login with (use CloudBase Web Auth skill)
@cloudbase/js-sdk@2.x - Node.js code that uses (use CloudBase Node Auth skill)
@cloudbase/node-sdk - Non-auth CloudBase features (database, storage, etc.)
当你需要通过原生HTTP API调用CloudBase Auth时,即可使用该技能,例如:
- 非Node后端(Go、Python、Java、PHP等)
- 使用curl或语言原生HTTP客户端的集成测试或管理脚本
- 部署在CloudBase前端、自行管理令牌的网关或代理
请勿在以下场景使用该技能:
- 使用的前端Web登录(请使用CloudBase Web Auth技能)
@cloudbase/js-sdk@2.x - 使用的Node.js代码(请使用CloudBase Node Auth技能)
@cloudbase/node-sdk - CloudBase的非认证功能(数据库、存储等)
How to use this skill (for a coding agent)
如何使用该技能(面向编码Agent)
-
Clarify the scenario
- Confirm this code will call HTTP endpoints directly (not SDKs).
- Ask for:
- – CloudBase environment ID
env - /
clientId– HTTP auth client credentialsclientSecret
- Confirm whether the flow is login/sign-up, anonymous access, token management, or user operations.
-
Set common variables once
- Use a shared set of shell variables for base URL and headers, then reuse them across scenarios.
-
Pick a scenario from this file
- For login / sign-up, start with Scenarios 1–3.
- For token lifecycle, use Scenarios 4–6.
- For user info and profile changes, use Scenario 7.
-
Never invent endpoints or fields
- Treat the URLs and JSON shapes in this file as canonical.
- If you are unsure, consult the HTTP API docs under and the specific
/source-of-truth/auth/http-api/登录认证接口.info.mdxfiles.*.api.mdx
-
明确场景
- 确认代码将直接调用HTTP端点(而非SDK)。
- 需获取以下信息:
- – CloudBase环境ID
env - /
clientId– HTTP认证客户端凭证clientSecret
- 确认流程类型:登录/注册、匿名访问、令牌管理或用户操作。
-
一次性设置通用变量
- 为基础URL和请求头设置一组共享的Shell变量,然后在各场景中复用。
-
从本文档中选择对应场景
- 若为登录/注册场景,从场景1–3开始。
- 若为令牌生命周期管理,使用场景4–6。
- 若为用户信息和资料修改,使用场景7。
-
切勿自行编造端点或字段
- 请将本文档中的URL和JSON结构视为标准规范。
- 若有疑问,请查阅下的HTTP API文档及具体的
/source-of-truth/auth/http-api/登录认证接口.info.mdx文件。*.api.mdx
HTTP API basics
HTTP API基础
-
Base URL pattern
https://${env}.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1/...
-
Common headers
- – device or client identifier
x-device-id - – unique request ID for tracing
x-request-id - –
Authorizationfor user endpointsBearer <access_token> - Or HTTP basic auth () for client-credential style endpoints
-u clientId:clientSecret
-
Reusable shell variables
bash
env="your-env-id"
deviceID="backend-service-1"
requestID="$(uuidgen || echo manual-request-id)"
clientId="your-client-id"
clientSecret="your-client-secret"
base="https://${env}.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1"-
基础URL格式
https://${env}.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1/...
-
通用请求头
- – 设备或客户端标识符
x-device-id - – 用于追踪的唯一请求ID
x-request-id - – 用户端点需使用
AuthorizationBearer <access_token> - 客户端凭证式端点可使用HTTP基础认证()
-u clientId:clientSecret
-
可复用的Shell变量
bash
env="your-env-id"
deviceID="backend-service-1"
requestID="$(uuidgen || echo manual-request-id)"
clientId="your-client-id"
clientSecret="your-client-secret"
base="https://${env}.ap-shanghai.tcb-api.tencentcloudapi.com/auth/v1"Core concepts (HTTP perspective)
核心概念(HTTP视角)
- CloudBase Auth uses JWT access tokens plus refresh tokens.
- HTTP login/sign-up endpoints usually return both and
access_token.refresh_token - Most user-management endpoints require .
Authorization: Bearer ${accessToken} - Verification flows (SMS/email) use separate endpoints before sign-up.
verification
- CloudBase Auth使用JWT访问令牌和刷新令牌。
- HTTP登录/注册端点通常会同时返回和
access_token。refresh_token - 大多数用户管理端点需要携带。
Authorization: Bearer ${accessToken} - 验证流程(短信/邮箱)需在注册前调用独立的端点。
verification
Scenarios (flat list)
场景列表(扁平化)
Scenario 1: Sign-in with username/password
场景1:用户名/密码登录
bash
curl "${base}/signin" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"username":"test@example.com","password":"your password"}'- Use when the user already has a username (phone/email/username) and password.
- Response includes ,
access_token, and user info.refresh_token
bash
curl "${base}/signin" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"username":"test@example.com","password":"your password"}'- 适用于用户已拥有用户名(手机号/邮箱/用户名)和密码的场景。
- 响应包含、
access_token和用户信息。refresh_token
Scenario 2: SMS sign-up with verification code
场景2:短信验证码注册
- Send verification code
bash
curl "${base}/verification" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"phone_number":"+86 13800000000"}'- Verify code
bash
curl "${base}/verification/verify" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"verification_code":"000000","verification_id":"<from previous step>"}'- Sign up
bash
curl "${base}/signup" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{
"phone_number":"+86 13800000000",
"verification_code":"000000",
"verification_token":"<from verify>",
"name":"手机用户",
"password":"password",
"username":"username"
}'- Use this pattern for SMS or email-based registration; adapt fields per docs.
- 发送验证码
bash
curl "${base}/verification" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"phone_number":"+86 13800000000"}'- 验证验证码
bash
curl "${base}/verification/verify" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"verification_code":"000000","verification_id":"<from previous step>"}'- 完成注册
bash
curl "${base}/signup" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{
"phone_number":"+86 13800000000",
"verification_code":"000000",
"verification_token":"<from verify>",
"name":"手机用户",
"password":"password",
"username":"username"
}'- 该模式适用于短信或邮箱注册;可根据文档调整字段。
Scenario 3: Anonymous login
场景3:匿名登录
bash
curl "${base}/signin-anonymously" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{}'- Returns tokens for an anonymous user that you can later upgrade via sign-up.
bash
curl "${base}/signin-anonymously" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{}'- 返回匿名用户的令牌,后续可通过注册将其升级为正式用户。
Scenario 4: Exchange refresh token for new access token
场景4:使用刷新令牌换取新的访问令牌
bash
curl "${base}/token" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"grant_type":"refresh_token","refresh_token":"<refresh_token>"}'- Use when the frontend or another service sends you a refresh token and you need a fresh access token.
bash
curl "${base}/token" \
-X POST \
-H "x-device-id: ${deviceID}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"grant_type":"refresh_token","refresh_token":"<refresh_token>"}'- 当前端或其他服务向你发送刷新令牌,而你需要获取新的访问令牌时使用。
Scenario 5: Introspect and validate a token
场景5:令牌自省与验证
bash
curl "${base}/token/introspect?token=${accessToken}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}"- Use for backend validation of tokens before trusting them.
- Response indicates whether the token is active and may include claims.
bash
curl "${base}/token/introspect?token=${accessToken}" \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}"- 适用于后端在信任令牌前对其进行验证。
- 响应会标明令牌是否有效,并可能包含声明信息。
Scenario 6: Revoke a token (logout)
场景6:吊销令牌(登出)
bash
curl "${base}/revoke" \
-X POST \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"token":"${accessToken}"}'- Call when logging a user out from the backend or on security events.
bash
curl "${base}/revoke" \
-X POST \
-H "x-request-id: ${requestID}" \
-u "${clientId}:${clientSecret}" \
--data-raw '{"token":"${accessToken}"}'- 当从后端登出用户或发生安全事件时调用。
Scenario 7: Basic user operations (me, update password, delete)
场景7:基础用户操作(获取自身信息、修改密码、删除账户)
bash
undefinedbash
undefinedGet current user
Get current user
curl "${base}/user/me"
-H "Authorization: Bearer ${accessToken}"
-H "Authorization: Bearer ${accessToken}"
curl "${base}/user/me"
-H "Authorization: Bearer ${accessToken}"
-H "Authorization: Bearer ${accessToken}"
Change password
Change password
curl "${base}/user/password"
-X PATCH
-H "Authorization: Bearer ${accessToken}"
--data-raw '{"old_password":"old","new_password":"new"}'
-X PATCH
-H "Authorization: Bearer ${accessToken}"
--data-raw '{"old_password":"old","new_password":"new"}'
- Other endpoints:
- `DELETE ${base}/user/me` – delete current user.
- `${base}/user/providers` plus bind/unbind APIs – manage third-party accounts.
- Always secure these operations and log only minimal necessary data.curl "${base}/user/password"
-X PATCH
-H "Authorization: Bearer ${accessToken}"
--data-raw '{"old_password":"old","new_password":"new"}'
-X PATCH
-H "Authorization: Bearer ${accessToken}"
--data-raw '{"old_password":"old","new_password":"new"}'
- 其他端点:
- `DELETE ${base}/user/me` – 删除当前用户。
- `${base}/user/providers`及绑定/解绑API – 管理第三方账户。
- 请始终确保这些操作的安全性,仅记录必要的最少数据。