跳到正文

Auth 与身份

终端用户身份认证即服务——用户、会话、JWT/JWKS 校验、OAuth 与 GDPR/CCPA 同意——基于 infrai 自研身份引擎,一把 key 打通。

1. 概览

基础路径: https://api.infrai.cc/v1/auth
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/auth capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/auth/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. 方法 (17)

2.1auth.user.create

POST /v1/auth/user/create

在 infrai 自研身份引擎中创建终端用户。支持 idempotency_key。

参数

名称类型必填说明
emailstring
必填
用户邮箱地址。
format: email
passwordstring可选可选的初始密码(依赖 vendor)。
metadataRecord<string, unknown>可选存储在用户上的任意键值元数据。
vendor"infrai_native" | null可选可选的显式 vendor 锁定。
mode"default_vendor" | "verified_account"可选预置模式——managed。
default: "default_vendor"
idempotency_keystring可选客户端提供的幂等键。

返回

AuthUser { user_id, email, email_verified, created_at }
名称类型说明
user_idstring关联此资源的用户标识
pattern: ^au_usr_[A-Za-z0-9]{20,}$
emailstring邮箱地址
format: email
email_verifiedboolean邮箱地址是否已验证
default: false
phonestring | nullE.164 格式的电话号码
mfa_enabledboolean该用户是否启用了多因素认证
default: false
created_atstring资源创建时间(ISO 8601)
format: date-time
last_login_atstring | nullISO 8601 时间戳:the last successful login(ISO 8601)
format: date-time
metadataobject | null附加在此资源上的任意键值元数据
vendorstring | null粘滞:该用户的记录供应商。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/user/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com"}'

2.2auth.user.get

GET /v1/auth/user/get/{user_id}

按 user_id 获取单个认证用户。

参数

名称类型必填说明
user_idstring
必填
用户 id。

返回

AuthUser
名称类型说明
user_idstring关联此资源的用户标识
pattern: ^au_usr_[A-Za-z0-9]{20,}$
emailstring邮箱地址
format: email
email_verifiedboolean邮箱地址是否已验证
default: false
phonestring | nullE.164 格式的电话号码
mfa_enabledboolean该用户是否启用了多因素认证
default: false
created_atstring资源创建时间(ISO 8601)
format: date-time
last_login_atstring | nullISO 8601 时间戳:the last successful login(ISO 8601)
format: date-time
metadataobject | null附加在此资源上的任意键值元数据
vendorstring | null粘滞:该用户的记录供应商。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/user/get/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.3auth.user.get_by_email

GET /v1/auth/user/get_by_email

按邮箱地址查找认证用户。

参数

名称类型必填说明
emailstring
必填
用户邮箱地址。

返回

AuthUser
名称类型说明
user_idstring关联此资源的用户标识
pattern: ^au_usr_[A-Za-z0-9]{20,}$
emailstring邮箱地址
format: email
email_verifiedboolean邮箱地址是否已验证
default: false
phonestring | nullE.164 格式的电话号码
mfa_enabledboolean该用户是否启用了多因素认证
default: false
created_atstring资源创建时间(ISO 8601)
format: date-time
last_login_atstring | nullISO 8601 时间戳:the last successful login(ISO 8601)
format: date-time
metadataobject | null附加在此资源上的任意键值元数据
vendorstring | null粘滞:该用户的记录供应商。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/user/get_by_email \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.4auth.user.list

GET /v1/auth/user/list

按游标分页列出账户下的认证用户。

参数

名称类型必填说明
cursorstring可选不透明分页游标。
limitnumber可选返回条目的最大数量。

返回

{ items: AuthUser[], next_cursor?: string }
名称类型说明
itemsobject[]user records列表
next_cursorstring | null下一页游标;null 表示最后一页
totalintegeritems in this page数量

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/user/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.5auth.user.update

PATCH /v1/auth/user/update/{user_id}

更新已有认证用户的可变字段(metadata、手机号、MFA)。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。
pattern: ^au_usr_[A-Za-z0-9]{20,}$
metadataRecord<string, unknown>可选存储在用户上的任意键值元数据。
email_verifiedboolean可选将用户邮箱标记为已验证。
mfa_enabledboolean可选为用户启用或停用 MFA。
idempotency_keystring可选客户端提供的幂等键。

返回

AuthUser
名称类型说明
user_idstring关联此资源的用户标识
pattern: ^au_usr_[A-Za-z0-9]{20,}$
emailstring邮箱地址
format: email
email_verifiedboolean邮箱地址是否已验证
default: false
phonestring | nullE.164 格式的电话号码
mfa_enabledboolean该用户是否启用了多因素认证
default: false
created_atstring资源创建时间(ISO 8601)
format: date-time
last_login_atstring | nullISO 8601 时间戳:the last successful login(ISO 8601)
format: date-time
metadataobject | null附加在此资源上的任意键值元数据
vendorstring | null粘滞:该用户的记录供应商。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X PATCH https://api.infrai.cc/v1/auth/user/update/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "sample"}'

2.6auth.user.delete

DELETE /v1/auth/user/delete/{user_id}

删除认证用户并级联吊销其会话。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。

返回

{ ok: boolean }
名称类型说明
okboolean用户是否已删除
user_idstring | null已删除的用户标识符

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/auth/user/delete/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.7auth.session.create

POST /v1/auth/session/create

为用户签发已认证会话。可能返回 AUTH_MFA_REQUIRED。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。
pattern: ^au_usr_[A-Za-z0-9]{20,}$
method"password" | "magic_link" | "otp" | "oauth" | "passkey"可选会话使用的认证方式。
default: "password"
mfa_factorstring可选设置 require_mfa 时的 MFA 因子 / 验证码。
require_mfaboolean可选签发会话需要 MFA 因子。
default: false
idempotency_keystring可选客户端提供的幂等键。

返回

Session { session_id, access_token, refresh_token, expires_at }
名称类型说明
challenge_idstring认证挑战标识符
method"password" | "magic_link" | "otp" | "oauth" | "passkey"所用的认证方式(如 email_otp、oauth、password)
redirect_uristring | null用于 oauth 方式。
expires_atstring资源或令牌过期时间(ISO 8601)
format: date-time

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/session/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "sample"}'

2.8auth.session.verify

GET /v1/auth/session/verify/{session_id}

依据 infrai JWKS 校验 session_id / JWT,并返回 Session。

参数

名称类型必填说明
session_idstring
必填
会话 id。

返回

{ valid: boolean, user_id?, expires_at? }
名称类型说明
session_idstringsession的唯一标识符
user_idstring关联此资源的用户标识
pattern: ^au_usr_[A-Za-z0-9]{20,}$
started_atstring执行开始时间(ISO 8601)
format: date-time
expires_atstring资源或令牌过期时间(ISO 8601)
format: date-time
ipstring | null创建会话的 IP 地址
uastring | null会话创建请求中的 User-Agent 字符串
mfa_factorstring | null活跃 MFA 因子(参见 enums/AuthFactor)。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/session/verify/SESSION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.9auth.session.refresh

POST /v1/auth/session/refresh

用 refresh token 换取新会话;强制 5 分钟冷却(AUTH_REFRESH_TOO_FREQUENT)。支持 idempotency_key。

参数

名称类型必填说明
refresh_tokenstring
必填
用于换取新会话的有效 refresh token。
≥ 1 chars
idempotency_keystring可选客户端提供的幂等键。

返回

Session
名称类型说明
access_tokenstring用于 API 认证的短期访问令牌
refresh_tokenstring用于获取新访问令牌的长期令牌
expires_ininteger访问令牌过期倒计时(秒)。
≥ 1

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/session/refresh \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "sample"}'

2.10auth.session.revoke

POST /v1/auth/session/revoke/{session_id}

按 session_id 吊销单个会话。支持 idempotency_key。

参数

名称类型必填说明
session_idstring
必填
会话 id。
≥ 1 chars
idempotency_keystring可选客户端提供的幂等键。

返回

{ ok: boolean }
名称类型说明
okboolean会话是否已吊销
countintegersessions revoked (auth.session.revoke_all_for_user only)数量

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/session/revoke/SESSION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"session_id": "sample"}'

2.11auth.session.revoke_all_for_user

POST /v1/auth/session/revoke_all_for_user/{user_id}

吊销某用户的全部活跃会话(如改密 / 全端登出)。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。
pattern: ^au_usr_[A-Za-z0-9]{20,}$
except_session_idstring可选保留此会话;吊销其余全部。

返回

{ revoked: number }
名称类型说明
okboolean会话是否已吊销
countintegersessions revoked (auth.session.revoke_all_for_user only)数量

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/session/revoke_all_for_user/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "sample"}'

2.12auth.session.list_for_user

GET /v1/auth/session/list_for_user/{user_id}

列出指定用户的活跃会话。

参数

名称类型必填说明
user_idstring
必填
用户 id。

返回

{ items: Session[] }
名称类型说明
itemsobject[]session records列表

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/session/list_for_user/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.13auth.consent.grant

POST /v1/auth/consent/grant/{user_id}

为用户 / 类别记录一条 GDPR/CCPA 同意授予。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。
pattern: ^au_usr_[A-Za-z0-9]{20,}$
category"marketing" | "analytics" | "essential" | "third_party"
必填
同意类别,如 marketing 或 analytics。
sourcestring可选同意的采集来源。
default: "explicit"
idempotency_keystring可选客户端提供的幂等键。

返回

{ ok: boolean }
名称类型说明
okboolean操作是否成功
consent_idstring同意记录的标识符(仅 auth.consent.grant)
user_idstring用户标识
categorystring受影响的同意类别
grantedboolean是否已授予同意(仅 auth.consent.grant)
granted_atstring | null授予同意的 ISO 8601 时间戳(仅 auth.consent.grant)
revoked_atstring | null撤销同意的 ISO 8601 时间戳(如有)(仅 auth.consent.grant)
sourcestring同意的采集方式,如 "explicit"(仅 auth.consent.grant)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/consent/grant/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "sample", "category": "marketing"}'

2.14auth.consent.revoke

POST /v1/auth/consent/revoke/{user_id}

撤回此前为用户 / 类别授予的同意。支持 idempotency_key。

参数

名称类型必填说明
user_idstring
必填
用户 id。
pattern: ^au_usr_[A-Za-z0-9]{20,}$
category"marketing" | "analytics" | "essential" | "third_party"
必填
同意类别,如 marketing 或 analytics。
idempotency_keystring可选客户端提供的幂等键。

返回

{ ok: boolean }
名称类型说明
okboolean操作是否成功
consent_idstring同意记录的标识符(仅 auth.consent.grant)
user_idstring用户标识
categorystring受影响的同意类别
grantedboolean是否已授予同意(仅 auth.consent.grant)
granted_atstring | null授予同意的 ISO 8601 时间戳(仅 auth.consent.grant)
revoked_atstring | null撤销同意的 ISO 8601 时间戳(如有)(仅 auth.consent.grant)
sourcestring同意的采集方式,如 "explicit"(仅 auth.consent.grant)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/consent/revoke/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "sample", "category": "marketing"}'

2.15auth.consent.check

GET /v1/auth/consent/check/{user_id}/{category}

检查用户当前是否持有某类别的同意(布尔)。

参数

名称类型必填说明
user_idstring
必填
用户 id。
categorystring
必填
同意类别,如 marketing 或 analytics。

返回

{ granted: boolean, source?, granted_at? }
名称类型说明
resultboolean该用户/类别当前是否已授予同意

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/consent/check/USER_ID/CATEGORY \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.16auth.consent.list_for_user

GET /v1/auth/consent/list_for_user/{user_id}

列出某用户跨 GDPR 类别的全部同意记录。

参数

名称类型必填说明
user_idstring
必填
用户 id。

返回

{ items: Array<{ category, granted, source?, granted_at? }> }
名称类型说明
itemsobject[]consent records列表

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/auth/consent/list_for_user/USER_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.17auth.identity.resolve

POST /v1/auth/identity/resolve

用你已自行验证的第三方身份,解析或创建统一终端用户——租户背书模型(对齐 Auth0/Clerk)。原生 Sign in with Apple 场景:你的后端先验 Apple identityToken(用 Apple JWKS 验签 + 校 iss/aud),再用 Apple sub 调用本接口,绑定并返回稳定的 infrai 用户。幂等:同一 (provider, value) 始终解析为同一 user_id。无需在 infrai 侧登记你的 app。

参数

名称类型必填说明
type"email" | "phone" | "external"
必填
身份类型:"external"(第三方 provider 主体)、"email" 或 "phone"。
e.g. email
valuestring
必填
身份值——external 时为 provider 主体(如 Apple 的 `sub`)。
e.g. user@example.com
providerstring可选external 身份的 provider,如 "apple"、"google"、"wechat"。
createboolean可选无匹配身份时是否创建新身份。
default: true
verifiedboolean可选标记身份已验证——你的后端验过 provider token 后置 true。
account_idstring可选解析身份时关联的账户 ID。

返回

{ user: AuthUser, identity: Identity, created: boolean }
名称类型说明
userobject已解析的终端用户记录
identityobject匹配到的身份记录(type/provider/value/user_id/verified/created_at)
createdboolean本次调用是否创建了新用户(仅 auth.identity.resolve)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/auth/identity/resolve \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type": "email", "value": "user@example.com"}'
高级:指定 vendor

默认情况下 infrai 会把每次调用智能路由到最佳可用供应商——无需自己挑选 vendor。作为高级逃生口,本能力支持可选的 vendor 入参以锁定某个供应商。本能力当前所有可用 vendor 可通过该能力 id 对应的 discovery 端点实时获取——参见 discovery API

GET /v1/discovery/{capability}

auth.user.create

3. 全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

auth.consent.checkGET /v1/auth/consent/check/{user_id}/{category}

Check whether a user currently holds consent for a given category (boolean).

参数 (2)
名称类型必填说明
categorystring必填Path parameter.
user_idstring必填Path parameter.
auth.consent.grantPOST /v1/auth/consent/grant/{user_id}

Record a GDPR/CCPA consent grant for a user/category. Accepts idempotency_key.

参数 (4)
名称类型必填说明
user_idstring必填Path param.
pattern: ^au_usr_[A-Za-z0-9]{20,}$
category"marketing" | "analytics" | "essential" | "third_party"必填Consent category (e.g. marketing, analytics)
sourcestring可选How consent was captured.
default: "explicit"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.consent.list_for_userGET /v1/auth/consent/list_for_user/{user_id}

List all consent records for a user across GDPR categories.

参数 (1)
名称类型必填说明
user_idstring必填Path parameter.
auth.consent.revokePOST /v1/auth/consent/revoke/{user_id}

Revoke a previously granted consent for a user/category. Accepts idempotency_key.

参数 (3)
名称类型必填说明
user_idstring必填Path param.
pattern: ^au_usr_[A-Za-z0-9]{20,}$
category"marketing" | "analytics" | "essential" | "third_party"必填Consent category (e.g. marketing, analytics)
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.email.change_confirmPOST /v1/auth/email/change_confirm

Confirm an email change with the single-use token from the new address; switches the user's email. Returns AUTH_TOKEN_REUSED on replay. Accepts idempotency_key.

参数 (2)
名称类型必填说明
tokenstring必填Authentication or verification token
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.email.change_requestPOST /v1/auth/email/change_request

Start an email change for a user; sends a single-use signed verification token to the NEW address (self-built, no BYOK). Accepts idempotency_key.

参数 (3)
名称类型必填说明
user_idstring必填User identifier associated with this resource
≥ 1 chars
new_emailstring必填New email address; the signed verification link is sent here.
≥ 3 charsformat: email
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.email.send_codePOST /v1/auth/email/send_code

Send a short-lived single-use email OTP to a user for verification or passwordless login (self-built). Accepts idempotency_key.

参数 (4)
名称类型必填说明
emailstring必填Email address
≥ 3 charsformat: email
purpose"verify" | "login"可选Purpose of the DNS record
default: "verify"
localestring可选End-user's current language (BCP-47, e.g. 'zh-CN' / 'en'); the OTP email is rendered in it (zh/en supported, default en). Pass your app's UI locale so the code reaches the user in their language.
e.g. zh-CN
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.email.verifyPOST /v1/auth/email/verify

Verify an email OTP AND log in: on success resolves-or-creates the unified user (passwordless signup) and mints a session, returning {verified, user_id, created, session_id, access_token, refresh_token, expires_at} — a one-call login matching Auth0/Clerk/Supabase verifyOtp. Pass login=false for a bare code-check. Wrong/expired returns AUTH_CODE_INVALID. Accepts idempotency_key.

参数 (3)
名称类型必填说明
emailstring必填Email address
≥ 3 charsformat: email
codestring必填Authorization code from the OAuth provider
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.identity.addPOST /v1/auth/identity/add/{user_id}

Bind an additional login identity (email/phone/external) to an existing user. Idempotent if already this user's; IDENTITY_ALREADY_LINKED if another user owns it (no auto-merge).

参数 (7)
名称类型必填说明
user_idstring必填Path parameter.
type"email" | "phone" | "external"必填Identity kind.
e.g. email
valuestring必填The identity address/subject — an email, an E.164 phone, or a provider subject id (must match `type`).
e.g. user@example.com
providerstring | null可选For type=external: the provider id (e.g. wechat, google, github).
createboolean | null可选resolve(): create a unified user when none matches (default true).
default: true
verifiedboolean | null可选Mark the identity verified on attach (e.g. a tenant-vouched external subject).
account_idstring | null可选Tenant scope (defaults to the authenticated account).
auth.identity.getPOST /v1/auth/identity/get

Look up the end-user that owns a given identity (email/phone/external subject) without creating one; returns IDENTITY_NOT_FOUND if unknown.

参数 (6)
名称类型必填说明
type"email" | "phone" | "external"必填Identity kind.
e.g. email
valuestring必填The identity address/subject — an email, an E.164 phone, or a provider subject id (must match `type`).
e.g. user@example.com
providerstring | null可选For type=external: the provider id (e.g. wechat, google, github).
createboolean | null可选resolve(): create a unified user when none matches (default true).
default: true
verifiedboolean | null可选Mark the identity verified on attach (e.g. a tenant-vouched external subject).
account_idstring | null可选Tenant scope (defaults to the authenticated account).
auth.identity.listGET /v1/auth/identity/list/{user_id}

List every login identity (email/phone/external) attached to a user.

参数 (1)
名称类型必填说明
user_idstring必填Path parameter.
auth.identity.removeDELETE /v1/auth/identity/remove/{user_id}/{identity_id}

Unlink one identity from a user; refuses IDENTITY_LAST_REMAINING when it is the user's only remaining identity.

参数 (2)
名称类型必填说明
identity_idstring必填Path parameter.
user_idstring必填Path parameter.
auth.identity.resolvePOST /v1/auth/identity/resolve

Unified login/register: resolve a (tenant-vouched) email, phone, or external-provider identity to its end-user, minting the user + identity if unknown. type=external + provider (e.g. 'wechat') + value=<subject> handles any third-party login; one person who arrives via different identities maps to the SAME user_id.

参数 (6)
名称类型必填说明
type"email" | "phone" | "external"必填Identity kind.
e.g. email
valuestring必填The identity address/subject — an email, an E.164 phone, or a provider subject id (must match `type`).
e.g. user@example.com
providerstring | null可选For type=external: the provider id (e.g. wechat, google, github).
createboolean | null可选resolve(): create a unified user when none matches (default true).
default: true
verifiedboolean | null可选Mark the identity verified on attach (e.g. a tenant-vouched external subject).
account_idstring | null可选Tenant scope (defaults to the authenticated account).
auth.oauth.authorize_urlGET /v1/auth/oauth/authorize_url

Build the provider authorize URL (provider must be one of the enabled set — see auth.oauth.providers) with state, nonce and PKCE challenge; return_to/redirect_uri must be in the account's registered allowlist.

参数 (3)
名称类型必填说明
provider"google" | "github" | "apple" | "facebook"必填OAuth provider name (e.g. google, github)
return_tostring | null可选Unified-brand transit (preferred): final web URL or app deep link to 302 back to after Infrai's transit endpoint completes the flow. Must be in the account's allowlist.
e.g. https://app.example.com/auth/done
redirect_uristring | null可选Legacy customer-BFF: the caller's own provider redirect URI (used when `return_to` is absent). Must be in the account's allowlist.
format: urie.g. https://app.example.com/oauth/callback
auth.oauth.callbackPOST /v1/auth/oauth/callback

Complete the OAuth flow: validate state + redirect_uri, exchange the code, link/create the user and mint a session. Honest typed error if the provider is not configured.

参数 (6)
名称类型必填说明
provider"google" | "github" | "apple" | "facebook"必填OAuth provider name (e.g. google, github)
codestring必填Authorization code from the OAuth provider
≥ 1 chars
statestring必填Current lifecycle state of this resource
≥ 1 chars
redirect_uristring必填Redirect URI registered with the OAuth provider
≥ 1 charsformat: uri
code_verifierstring | null可选PKCE verifier matching the challenge from authorize_url.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.oauth.providersGET /v1/auth/oauth/providers

List the OAuth providers an end user can sign in with right now, each flagged ready (real client_id configured), plus the unified consent-screen brand. The runtime companion to the AuthProvider enum in discovery.

无请求参数。

auth.password.changePOST /v1/auth/password/change

Change a user's password after verifying the current one (AUTH_INVALID_CREDENTIALS on mismatch); argon2id re-hash. Accepts idempotency_key.

参数 (4)
名称类型必填说明
user_idstring必填User identifier associated with this resource
≥ 1 chars
current_passwordstring必填Current password for verification
≥ 1 chars
new_passwordstring必填New password for the account
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.password.reset_confirmPOST /v1/auth/password/reset_confirm

Confirm a password reset with {email, code, new_password} — verifies the 6-digit code from reset_request, re-hashes (argon2id) and revokes all sessions. Wrong/expired code returns AUTH_CODE_INVALID; weak password returns AUTH_PASSWORD_TOO_WEAK. Accepts idempotency_key.

参数 (4)
名称类型必填说明
emailstring必填Email address
format: email
codestring必填Authorization code from the OAuth provider
4–8 chars
new_passwordstring必填New password for the account
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.password.reset_requestPOST /v1/auth/password/reset_request

Request a password reset (code-style, Supabase pattern); always returns 200 (no user-existence leak) and emails a single-use 6-digit code when the email is known. Accepts idempotency_key.

参数 (2)
名称类型必填说明
emailstring必填Email address
≥ 3 charsformat: email
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.phone.send_codePOST /v1/auth/phone/send_code

Send a short-lived single-use phone (SMS) OTP to a user (self-built; SMS delivery depends on infra.sms). Accepts idempotency_key.

参数 (4)
名称类型必填说明
phonestring必填Phone number in E.164 format
≥ 3 chars
purpose"verify" | "login"可选Purpose of the DNS record
default: "verify"
localestring可选End-user's current language (BCP-47, e.g. 'zh-CN' / 'en'); the OTP SMS is rendered in it (zh/en supported, default en). Pass your app's UI locale so the code reaches the user in their language.
e.g. zh-CN
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.phone.verifyPOST /v1/auth/phone/verify

Verify a phone OTP AND log in: on success resolves-or-creates the unified user (passwordless signup) and mints a session, returning {verified, user_id, created, session_id, access_token, refresh_token, expires_at} — a one-call login matching Auth0/Clerk/Supabase. Pass login=false for a bare code-check. Wrong/expired returns AUTH_CODE_INVALID. Accepts idempotency_key.

参数 (3)
名称类型必填说明
phonestring必填Phone number in E.164 format
≥ 3 chars
codestring必填Authorization code from the OAuth provider
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.session.createPOST /v1/auth/session/create

Mint an authenticated session for a user; routes to the user's pinned vendor. May return AUTH_MFA_REQUIRED. Accepts idempotency_key.

参数 (5)
名称类型必填说明
user_idstring必填User identifier associated with this resource
pattern: ^au_usr_[A-Za-z0-9]{20,}$
method"password" | "magic_link" | "otp" | "oauth" | "passkey"可选Authentication method used (e.g. email_otp, oauth, password)
default: "password"
mfa_factorstring | null可选MFA factor / code when require_mfa.
require_mfaboolean可选Whether MFA is required to complete authentication
default: false
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.session.list_for_userGET /v1/auth/session/list_for_user/{user_id}

List active sessions for a given user.

参数 (1)
名称类型必填说明
user_idstring必填Path parameter.
auth.session.refreshPOST /v1/auth/session/refresh

Exchange a refresh token for a new session; enforces 5-min cooldown (AUTH_REFRESH_TOO_FREQUENT). Accepts idempotency_key.

参数 (2)
名称类型必填说明
refresh_tokenstring必填Long-lived token used to obtain new access tokens
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.session.revokePOST /v1/auth/session/revoke/{session_id}

Revoke a single session by session_id. Accepts idempotency_key.

参数 (2)
名称类型必填说明
session_idstring必填Path param; the session to revoke.
≥ 1 chars
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.session.revoke_all_for_userPOST /v1/auth/session/revoke_all_for_user/{user_id}

Revoke all active sessions for a user (e.g. password reset / logout-everywhere). Accepts idempotency_key.

参数 (2)
名称类型必填说明
user_idstring必填Path param; revoke all this user's active sessions.
pattern: ^au_usr_[A-Za-z0-9]{20,}$
except_session_idstring | null可选Keep this one session alive (e.g. the current browser).
auth.session.verifyGET /v1/auth/session/verify/{session_id}

Verify a session_id / JWT against the vendor JWKS (RS256+ES256) and return the Session.

参数 (1)
名称类型必填说明
session_idstring必填Path parameter.
auth.token.jwksGET /v1/auth/token/jwks

Return the public JWKS (EdDSA) for offline verification of Infrai-issued access JWTs — clients verify tokens with zero round-trips.

无请求参数。

auth.user.createPOST /v1/auth/user/create

Create an auth user across a vendor (Clerk/WorkOS/Supabase Auth). Pins the vendor of record (sticky-on-resource). Accepts idempotency_key.

参数 (6)
名称类型必填说明
emailstring必填Email address
format: email
passwordstring | null可选Optional initial password (vendor-dependent).
metadataobject | null可选Arbitrary key-value metadata attached to this resource
vendor"infrai_native" | null可选Explicit vendor pin (auth is self-operated: infrai_native only).
mode"default_vendor" | "verified_account"可选Delivery mode or operation mode
default: "default_vendor"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
auth.user.deleteDELETE /v1/auth/user/delete/{user_id}

Delete an auth user and cascade-revoke its sessions. Accepts idempotency_key.

参数 (1)
名称类型必填说明
user_idstring必填Path parameter.
auth.user.getGET /v1/auth/user/get/{user_id}

Fetch a single auth user by user_id from its pinned vendor.

参数 (1)
名称类型必填说明
user_idstring必填Path parameter.
auth.user.get_by_emailGET /v1/auth/user/get_by_email

Look up an auth user by email address.

无请求参数。

auth.user.listGET /v1/auth/user/list

Cursor-paginated list of auth users for the account.

无请求参数。

auth.user.updatePATCH /v1/auth/user/update/{user_id}

Update mutable fields (metadata, phone, MFA) of an existing auth user. Accepts idempotency_key.

参数 (5)
名称类型必填说明
user_idstring必填Path param; the user to update.
pattern: ^au_usr_[A-Za-z0-9]{20,}$
metadataobject | null可选Arbitrary key-value metadata attached to this resource
email_verifiedboolean | null可选Whether the email address has been verified
mfa_enabledboolean | null可选Whether multi-factor authentication is enabled for this user
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry

4. 完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · auth — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) auth.user.create — POST /v1/auth/user/create · Create an auth user across a vendor (Clerk/WorkOS/Supabase Auth). Pins the vendor of record (sticky-on-resource). Accepts idempotency_key.
r1 = show("auth.user.create", infrai("POST", "/v1/auth/user/create", {"email":"user@example.com"}))

# 2) auth.session.create — POST /v1/auth/session/create · Mint an authenticated session for a user; routes to the user's pinned vendor. May return AUTH_MFA_REQUIRED. Accepts idempotency_key.
r2 = show("auth.session.create", infrai("POST", "/v1/auth/session/create", {"user_id":"sample"}))

# 3) auth.user.get_by_email — GET /v1/auth/user/get_by_email · Look up an auth user by email address.
r3 = show("auth.user.get_by_email", infrai("GET", "/v1/auth/user/get_by_email"))