Files
upstream-mirror e7da97194a
Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
snapshot of https://github.com/twentyhq/twenty.git (main, 2026-09-17; blobs > 131072B omitted)
2026-09-17 23:28:13 +05:00

190 lines
7.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: OAuth
icon: key
description: PKCE を用いた認可コードフロー、およびサーバー間アクセス向けのクライアントクレデンシャル。
---
Twenty は、ユーザー向けアプリでは認可コード + PKCE、サーバー間アクセスではクライアントクレデンシャルを用いた OAuth 2.0 を実装しています。 クライアントは [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591) に従って動的に登録され、ダッシュボードでの手動セットアップは不要です。
## OAuth を使用するタイミング
| シナリオ | 認証方法 |
| ---------------------- | ---------------------------------------------------------------------------- |
| 社内向けスクリプト、自動化 | [API キー](/l/ja/developers/extend/api#authentication) |
| ユーザーの代理として動作する外部アプリ | **OAuth — 認可コード** |
| サーバー間、ユーザーコンテキストなし | **OAuth — クライアントクレデンシャル** |
| UI 拡張機能を備えた Twenty アプリ | [アプリ](/l/ja/developers/extend/apps/getting-started/quick-start)(OAuth は自動で処理されます) |
## クライアントを登録
Twenty は [RFC 7591](https://datatracker.ietf.org/doc/html/rfc7591) に準拠した**動的クライアント登録**をサポートします。 手動セットアップは不要—プログラムで登録します:
```bash
POST /oauth/register
Content-Type: application/json
{
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"],
"grant_types": ["authorization_code"],
"token_endpoint_auth_method": "client_secret_post"
}
```
**レスポンス:**
```json
{
"client_id": "abc123",
"client_secret": "secret456",
"client_name": "My Integration",
"redirect_uris": ["https://myapp.com/callback"]
}
```
<Warning>
`client_secret` は安全に保管してください—後から再取得することはできません。
</Warning>
## スコープ
| スコープ | アクセス |
| --------- | ---------------------------------------- |
| `api` | Core および Metadata API への読み取り/書き込みのフルアクセス |
| `profile` | 認証済みユーザーのプロフィール情報を読み取る |
スコープはスペース区切りの文字列で指定します: `scope=api profile`
## 認可コードフロー
アプリが Twenty ユーザーの代理として動作する場合にこのフローを使用します。
### 1. ユーザーを認可にリダイレクト
```
GET /oauth/authorize?
client_id=YOUR_CLIENT_ID&
response_type=code&
redirect_uri=https://myapp.com/callback&
scope=api&
state=random_state_value&
code_challenge=CHALLENGE&
code_challenge_method=S256
```
| パラメーター | 必須 | 説明 |
| ----------------------- | --- | ------------------------------------------------- |
| `client_id` | はい | 登録済みのクライアント ID |
| `response_type` | はい | `code` である必要があります |
| `redirect_uri` | はい | 登録済みのリダイレクト URI と一致している必要があります |
| `scope` | いいえ | スペース区切りのスコープ(既定は `api`) |
| `state` | 推奨 | CSRF 攻撃を防ぐためのランダムな文字列 |
| `code_challenge` | 推奨 | PKCE チャレンジ(ベリファイアの SHA-256 ハッシュを base64url エンコード) |
| `code_challenge_method` | 推奨 | PKCE 使用時は `S256` である必要があります |
ユーザーに同意画面が表示され、アクセスを許可または拒否します。
### 2. コールバックを処理
認可後、Twenty はあなたの `redirect_uri` にリダイレクトします:
```
https://myapp.com/callback?code=AUTH_CODE&state=random_state_value
```
`state` が送信した値と一致することを確認します。
### 3. コードをトークンに交換
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=AUTH_CODE&
redirect_uri=https://myapp.com/callback&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
code_verifier=YOUR_PKCE_VERIFIER
```
**レスポンス:**
```json
{
"access_token": "eyJhbG...",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "dGhpcyBpcyBh..."
}
```
### 4. アクセストークンを使用
```bash
GET /rest/companies
Authorization: Bearer ACCESS_TOKEN
```
### 5. 期限切れ時にリフレッシュ
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&
refresh_token=YOUR_REFRESH_TOKEN&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET
```
## クライアントクレデンシャルフロー
ユーザー操作のないサーバー間統合向け:
```bash
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
scope=api
```
返されるトークンは特定のユーザーに紐づかないワークスペースレベルのアクセス権を持ちます。
## サーバーディスカバリー
Twenty は標準のディスカバリーエンドポイントで OAuth 設定を公開しています:
```
GET /.well-known/oauth-authorization-server
```
これにより、すべてのエンドポイント、対応するグラントタイプ、スコープ、および機能が返されます—汎用的な OAuth クライアントを構築するのに役立ちます。
## API エンドポイント概要
| エンドポイント | 目的 |
| ----------------------------------------- | ----------------- |
| `/.well-known/oauth-authorization-server` | サーバーメタデータのディスカバリー |
| `/oauth/register` | 動的クライアント登録 |
| `/oauth/authorize` | ユーザー認可 |
| `/oauth/token` | トークンの交換とリフレッシュ |
| 環境 | ベース URL |
| ---------- | ------------------------ |
| **クラウド** | `https://api.twenty.com` |
| **セルフホスト** | `https://{your-domain}` |
## OAuth と API キー
| | APIキー | OAuth |
| --------------- | -------------- | ----------------- |
| **セットアップ** | 設定で生成 | クライアントを登録し、フローを実装 |
| **ユーザーコンテキスト** | なし(ワークスペースレベル) | 特定ユーザーの権限 |
| **最適な用途** | スクリプト、社内ツール | 外部アプリ、マルチユーザー統合 |
| **トークンローテーション** | 手動 | リフレッシュトークンにより自動 |
| **スコープによるアクセス** | API へのフルアクセス | スコープによりきめ細かな制御 |