> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fluz.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 驗證參考

> 使用您的 API 金鑰簽發使用者存取權杖的精確請求/回應格式。

如需概念性總覽，請參閱 [驗證](/concepts/authentication)。本頁記錄在交易圖譜上簽發權杖的精確 GraphQL 契約：

| 環境         | 端點                                                               |
| ---------- | ---------------------------------------------------------------- |
| Staging    | `https://transactional-graph.staging.fluzapp.com/api/v1/graphql` |
| Production | `https://transactional-graph.fluzapp.com/api/v1/graphql`         |

## `generateUserAccessToken`

使用您應用程式的 **API key** 簽發使用者存取權杖。API key 會以 `Authorization: Basic <API_KEY>` 標頭傳送——永遠不會作為 GraphQL 參數傳遞。此權杖會為一組 `userId` / `accountId`（在開發者主控台的 API key 旁顯示）簽發，並攜帶您請求的 scopes。

### 請求

```http theme={null}
POST /api/v1/graphql HTTP/1.1
Host: transactional-graph.staging.fluzapp.com
Authorization: Basic <API_KEY>
Content-Type: application/json

{
  "query": "mutation ($userId: UUID!, $accountId: UUID!, $scopes: [ScopeType!]!) { generateUserAccessToken(userId: $userId, accountId: $accountId, scopes: $scopes) { token scopes } }",
  "variables": {
    "userId": "<USER_ID>",
    "accountId": "<ACCOUNT_ID>",
    "scopes": ["LIST_OFFERS", "PURCHASE_GIFTCARD"]
  }
}
```

可選的 `seatId: UUID` 參數可用來選擇進行交易所使用的 seat；預設為最近建立的 seat。請參閱完整參數參考：[generateUserAccessToken](/api-reference/mutations/generate-user-access-token)。

### 回應

```json theme={null}
{
  "data": {
    "generateUserAccessToken": {
      "token": "eyJhbGciOi...",
      "scopes": ["LIST_OFFERS", "PURCHASE_GIFTCARD"]
    }
  }
}
```

在後續請求中將回傳的 `token` 以 `Authorization: Bearer <token>` 附上。權杖為短效的 JWT——到期時請重新簽發新權杖（參見 [替換過期的存取權杖](/get-started/refresh-expired-access-token)）。

### 要求

* 使用者必須已授予您的應用程式所請求的 scopes；未知或未被授予的 scopes 會導致 mutation 失敗。
* 產生權杖時不可請求 `PCI_COMPLIANCE`——該權限在應用程式層級授予符合 PCI 的開發者。

## 取得 `userId` / `accountId`

同樣以 `Basic <API_KEY>` 授權：

* [`getApplicationUsers`](/api-reference/queries/get-application-users) — 已對您的應用程式授權 scopes 的使用者及其帳戶。
* [`getAccountsByUserId`](/api-reference/queries/get-accounts-by-user-id) — 指定使用者的所有帳戶。
* [`getApplicationScopes`](/api-reference/queries/get-application-scopes) — 您的應用程式可用的 scopes。

## 客戶帳戶（OAuth 平台）

若您正在打造在客戶帳戶上運作的平台，客戶需先透過 OAuth 授權流程授權您的應用程式，而您的伺服器會在權杖交換端點交換所得的代碼——請參見 [OAuth 授權流程](/client-facing-o-auth-grant-flow) 與 [打造平台](/build-a-platform)。

## Scopes

請參見 [驗證](/concepts/authentication#scopes) 中的 scope 表。未知的 scopes 會導致 mutation 失敗。
