# 认证

> 使用 Veripass 为你的组织签发的 Bearer 令牌认证 API 请求。Webhook 则通过各自的 ingress binding 进行认证。

Source: https://docs.sommatic.ai/zh/api/authentication/ (updated 2026-11-26)

每个 API 请求都要表明发起者是谁。Sommatic AI 依据这一身份把你能看到的数据限定在所属组织内，并记录每次运行、
每个任务和每项变更是由谁完成的。

## 携带 Bearer 令牌

在每个请求的 `Authorization` 请求头中发送令牌：

```text
Authorization: Bearer <token>
```

令牌由 Sommatic AI 的身份权威 **Veripass** 为你的组织签发，包含你的身份、所属组织和角色，从而让每一项敏感操作都绑定到
具体的执行者和组织。

**curl**

```bash
curl "https://api.sommatic.ai/work-management/task/inbox?user_id=$USER_IDENTITY&page=1&pageSize=25" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch('https://api.sommatic.ai/platform-infrastructure/credential/organization-id?search=' + organizationId, {
  headers: { Authorization: `Bearer ${token}` },
});
```

**React SDK**

```javascript
import { PlatformInfrastructureCredentialService } from '@sommatic/react-sdk';

const credentials = new PlatformInfrastructureCredentialService({ apiKey: token });
const response = await credentials.getByParameters({ queryselector: 'organization-id', search: organizationId });
```

没有有效令牌的请求会被拒绝，返回 HTTP 401：

```json
{ "status": 401, "success": false, "message": "Unauthorized", "result": null }
```

> **注意: 像对待密码一样对待令牌**
>
> 令牌只应保存在服务器端或当前用户的会话中。不要提交到代码仓库，不要放进 `VITE_` 变量或任何会下发到浏览器的打包文件，
> 也不要放在 URL 中。

## Webhook 按 binding 认证

`POST /workflow-orchestration/trigger/webhooks/:mode/:bindingIdentifier` 是唯一不接收 Bearer 令牌的接口：
调用工作流的外部系统通常没有 Veripass 身份。每个 Webhook 都通过一个 **ingress binding** 对外暴露，binding 在其
`authentication` 配置块中声明调用方如何认证：

| `authentication.mode` | binding 的要求                                    |
| --------------------- | ---------------------------------------------- |
| `api-key`             | binding 的 `allowed_api_keys` 中的某个密钥。           |
| `oauth2`              | 具备 binding `oauth_scopes` 的 OAuth 2 令牌。        |
| `veripass-session`    | 按 binding 的 `veripass_policy` 校验的 Veripass 会话。 |
| `service-token`       | 服务令牌。                                          |
| `custom`              | 该集成特有的认证方案。                                    |
| `none`                | 无需认证。仅用于不涉及真实数据的测试 binding。                    |

```json
{
  "slug": "ingress.http.inbound-requests",
  "ingress_kind": "http",
  "mode": "prod",
  "authentication": { "mode": "api-key", "allowed_api_keys": ["replace-with-a-long-random-key"] }
}
```

使用[触发器](https://docs.sommatic.ai/zh/api/reference/triggers.md)分组的接口创建和编辑 binding，这些接口需要 Bearer 令牌。
如何调用 Webhook、它的 `test` 与 `prod` 模式以及请求体，详见 [Webhook](https://docs.sommatic.ai/zh/workflows/webhooks.md)。

## 下一步

- [约定](https://docs.sommatic.ai/zh/api/conventions.md): 组织范围、选择器与分页。
- [安全](https://docs.sommatic.ai/zh/security.md): Sommatic AI 中的身份、凭据与审计。
