# auth api-tokens mint

> auth api-tokens mint — Turso 文件。
> Canonical HTML: https://tursodb.cn/zh-tw/docs/cli/auth/api-tokens/mint/
> Upstream Source (MIT): https://docs.turso.tech/cli/auth/api-tokens/mint
> Language: zh-TW

---
若要建立一個新的 API 權杖，並將其範圍限定於單一組織，請執行下列命令：

```bash
turso auth api-tokens mint <api-token-name> --org <organization-slug>
```

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">警告</div><div class="doc-callout-body">

**不受限制（跨組織）的權杖——亦即未帶 `--org` 的 mint——已棄用，並將於未來的版本中移除。** 建立新權杖時請一律傳入 `--org`。既有的不受限制權杖目前仍可運作，但您應盡快將其輪替為具範圍限定的權杖。

</div></div>


## 旗標

| 旗標 | 說明 |
| - | - |
| `--org` | 將權杖限制於特定的組織。 |
| `--group` | 將權杖限制於 `--org` 內的特定群組。需要 `--org` 與至少一個範圍。 |
| `--scope` | 授予權杖的權限。可重複使用。 |
| `--read-only` | `--scope read` 的簡寫。 |
| `--full-access` | 授予所有群組範圍的簡寫。不包含組織範圍。 |

## 組織範圍權杖

傳入 `--org` 可將權杖限制於單一組織：

```bash
turso auth api-tokens mint <api-token-name> --org <organization-slug>
```

組織範圍權杖只能管理該組織內的資源（群組、資料庫、成員）。對任何其他組織的請求都會被拒絕。

若未指定範圍，該權杖可以執行您在該組織中能做的所有事情。加上 `--scope` 即可加以限制。此時這些範圍會套用至組織中的每個群組：

```bash
# Read the audit logs, members, and billing data of the organization
turso auth api-tokens mint audit-reader --org my-org --scope org:read

# Create databases and mint SQL tokens in every group
turso auth api-tokens mint deploy-bot --org my-org --scope db:create --scope db:mint-token
```

組織範圍權杖可接受所有[群組範圍](#available-scopes)，以及下列組織範圍。具範圍的權杖無法管理成員或邀請、變更組織設定、轉移群組或資料庫，或 mint API 權杖。

### 組織範圍

這些範圍僅適用於組織範圍權杖，亦即未使用 `--group` 的權杖：

| 範圍 | 允許的操作 |
| - | - |
| `group:create` | 在組織中建立群組。 |
| `group:delete` | 刪除組織中的群組。 |
| `org:read` | 讀取組織資料：成員、邀請、帳務、發票、稽核日誌、SSO、JWKS 與 API 權杖。 |

讀取邀請與稽核日誌還需要您具備該組織的管理員或擁有者身分。`--full-access` 不包含這些範圍。若要授予，請以 `--scope` 逐一列出每個範圍。

## 群組範圍權杖

群組範圍權杖會固定於組織內的單一群組，並僅限於一組明確的操作。這正是適合那些應能在單一群組內佈建與管理資料庫、但無法觸及組織其他部分的自動化流程的形式。

您必須是該組織的管理員或擁有者，才能 mint 群組範圍權杖。

```bash
# Read-only access to one group
turso auth api-tokens mint deploy-bot --org my-org --group default --read-only

# Full access inside one group, but nothing outside it
turso auth api-tokens mint deploy-bot --org my-org --group default --full-access

# Fine-grained: provision and configure databases, mint SQL tokens
turso auth api-tokens mint deploy-bot --org my-org --group default \
  --scope db:create --scope db:configure --scope db:mint-token
```

### 可用範圍

`--scope` 可重複指定，並接受下列任一項：

| 範圍 | 允許的操作 |
| - | - |
| `read` | 所有 GET 形式的途徑：列出／取得資料庫與群組、組態、用量、執行個體、位置。 |
| `db:create` | 在群組內建立資料庫、從傾印檔初始化、還原。 |
| `db:delete` | 刪除群組內的資料庫。 |
| `db:configure` | 修補資料庫組態、喚醒、新增或移除執行個體。 |
| `db:mint-token` | 為群組內的資料庫簽發 SQL 引擎權杖或 TLS 用戶端憑證。 |
| `db:rotate-creds` | 輪替資料庫簽署金鑰，使先前為其簽發的所有 SQL 權杖失效。 |
| `group:configure` | 設定、重新命名、更新、取消封存群組，或新增與移除位置。 |
| `group:mint-token` | 簽發群組層級的 SQL 引擎權杖。 |
| `group:rotate-creds` | 輪替群組簽署金鑰，使群組權杖失效。在 AWS 上，資料庫範圍的權杖不會失效。 |

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">警告</div><div class="doc-callout-body">

`db:mint-token` 與 `db:rotate-creds` 刻意設計為各自獨立的範圍。簽發新的 SQL 憑證是累加性的；而輪替會使目前使用中的所有憑證失效，可能導致執行中的應用程式中斷。請僅將輪替權限授予需要它的自動化流程。

</div></div>


`--scope`、`--read-only` 與 `--full-access` 互斥——一次只能傳入一種形式。未知的範圍標籤會在請求送出前遭到拒絕。群組建立、群組刪除、群組轉移與 AWS 遷移在任何範圍下都無法透過群組範圍權杖觸及。

### 生命週期

群組範圍權杖是以群組的 UUID 固定，而非其名稱。刪除群組，或將其轉移至另一個組織，會連帶撤銷所有範圍限定於該群組的權杖。以相同名稱新建立的群組不會繼承先前群組的權杖。

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">警告</div><div class="doc-callout-body">

權杖值僅在建立時顯示一次。請將其存放在安全的地方。

</div></div>
