認証
IVGraphでは、JWTトークン(Notion OAuth経由で認証するWebユーザー向け)とサービストークン(LLMエージェントや自動化向け)の2つの認証方式を使用します。
Notion OAuth (JWT)
IVGraphは、NotionのOAuth2フローでユーザーを認証します。ユーザー名とパスワードによる登録はありません。
認証の流れ
User clicks "Sign in with Notion"
|
v
GET /api/integrations/auth/notion/
| -> Redirects to Notion consent screen
v
User authorizes IVGraph in Notion
|
v
Notion redirects to /api/integrations/auth/notion/callback?code=...
| -> Backend exchanges code for Notion token
| -> Creates/updates Django user
| -> Issues JWT tokens
v
Redirect to dashboard with tokens in URL fragment
JWTトークン
| トークン | 有効期間 | 用途 |
|---|---|---|
| アクセストークン | 4時間 | API認証 |
| リフレッシュトークン | 7日間 | 新しいアクセストークンの取得 |
アクセストークンの使用:
curl -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
"https://ivgraph.com/api/notion-graph/"
有効期限が切れたトークンの更新:
curl -X POST "https://ivgraph.com/api/auth/refresh/" \
-H "Content-Type: application/json" \
-d '{"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."}'
レスポンス:
{"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."}
ログアウト(リフレッシュトークンをブラックリストに登録):
curl -X POST "https://ivgraph.com/api/auth/logout/" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{"refresh": "<refresh_token>"}'
認証エンドポイント
| メソッド | エンドポイント | 説明 |
|---|---|---|
| GET | /api/integrations/auth/notion/ |
Notion OAuthフローを開始します |
| GET | /api/integrations/auth/notion/callback |
OAuthコールバック(内部用) |
| GET | /api/integrations/auth/notion/status |
OAuthの状態を確認します |
| POST | /api/auth/refresh/ |
アクセストークンを更新します |
| POST | /api/auth/logout/ |
リフレッシュトークンをブラックリストに登録します |
| GET | /api/auth/validate/ |
トークンが有効か確認します |
| GET | /api/auth/me/ |
現在のユーザー情報を取得します |
サービストークン(LLMエージェント向け)
サービストークンは、スコープで権限を限定し、V1読み取り専用APIに長期間アクセスできるようにするものです。LLMエージェント、自動化スクリプト、CI/CDパイプライン向けに設計されています。
トークンの形式
- 接頭辞:
ivg_(例:ivg_a1b2c3d4e5f6...) - 長さ:接頭辞の後に32文字のランダムな文字列が続きます
- 保存:データベースにはSHA-256ハッシュのみを保存します。トークンの元の値は作成時に一度だけ表示されます
トークンの作成
API経由(JWT認証が必要です):
curl -X POST "https://ivgraph.com/api/tokens/" \
-H "Authorization: Bearer <jwt_access_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "My LLM Agent",
"scopes": ["graph:search", "graph:read", "graph:neighbors"],
"workspace_ids": ["your-workspace-uuid"],
"expires_in_days": 90
}'
レスポンス(トークンは一度しか表示されません!):
{
"id": 1,
"name": "My LLM Agent",
"token": "ivg_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"prefix": "ivg_a1b2c3",
"scopes": ["graph:search", "graph:read", "graph:neighbors"],
"workspace_ids": ["your-workspace-uuid"],
"is_active": true,
"created_at": "2026-04-10T12:00:00Z",
"expires_at": "2026-07-09T12:00:00Z"
}
スコープ
| スコープ | 許可される操作 |
|---|---|
graph:search |
タイトルでノードを検索します |
graph:read |
ノードの詳細とページの内容を読み取ります |
graph:neighbors |
隣接ノードを取得し、経路をたどります |
制限
- トークン数はユーザーあたり最大10個です
- 各トークンには少なくとも1つのスコープが必要です
- 各トークンには少なくとも1つのworkspace_idが必要です(デフォルトではアクセスを拒否します)
- 有効期限(
expires_in_days)の指定は任意です。省略すると無期限になります
トークンの管理
| メソッド | エンドポイント | 説明 |
|---|---|---|
| GET | /api/tokens/ |
自分のトークン一覧を取得します(元の値は含まれません) |
| POST | /api/tokens/ |
新しいトークンを作成します |
| DELETE | /api/tokens/<id>/ |
トークンを失効させます(元に戻せません) |