API 利用ガイド
newland-core は Cloudflare Workers 上で動作するマルチテナント対応の認証 API です。 全てのエンドポイントに X-Tenant-Slug ヘッダーを付与して呼び出します。
エンドポイント一覧
| メソッド | パス | 認証 | 概要 |
|---|---|---|---|
| POST | /auth/register | 不要 | ユーザー登録 |
| POST | /auth/login | 不要 | ログイン・トークン発行 |
| POST | /auth/logout | Bearer | セッション無効化 |
| GET | /auth/me | Bearer | プロフィール取得 |
| POST | /auth/verify | 不要 | JWT アクセストークン検証 |
| GET | /health | 不要 | ヘルスチェック |
テナント解決
全リクエストに X-Tenant-Slug ヘッダーが必要です。
http
X-Tenant-Slug: your-tenant-slugテナントは KV (tenant:slug:{slug}) からキャッシュ解決されます。テナントが見つからない場合は 404 Tenant not found が返ります。
認証フロー
1. POST /auth/register → accessToken + refreshToken 取得
2. POST /auth/login → accessToken + refreshToken 取得
3. GET /auth/me → Authorization: Bearer {accessToken}
4. POST /auth/logout → Authorization: Bearer {accessToken}リクエスト例
ユーザー登録
bash
curl -X POST https://core.newland-studio.com/auth/register \
-H "Content-Type: application/json" \
-H "X-Tenant-Slug: your-tenant" \
-d '{"email":"user@example.com","password":"secret123","displayName":"山田 太郎"}'レスポンス (201):
json
{
"userId": "01HXxxxxxx",
"email": "user@example.com",
"accessToken": "eyJhbGci...",
"refreshToken": "eyJhbGci...",
"expiresIn": 3600
}ログイン
bash
curl -X POST https://core.newland-studio.com/auth/login \
-H "Content-Type: application/json" \
-H "X-Tenant-Slug: your-tenant" \
-d '{"email":"user@example.com","password":"secret123"}'レスポンス (200):
json
{
"accessToken": "eyJhbGci...",
"refreshToken": "eyJhbGci...",
"expiresIn": 3600,
"user": {
"id": "01HXxxxxxx",
"email": "user@example.com",
"displayName": "山田 太郎",
"role": "member"
}
}プロフィール取得
bash
curl https://core.newland-studio.com/auth/me \
-H "Authorization: Bearer {accessToken}" \
-H "X-Tenant-Slug: your-tenant"トークン検証
bash
curl -X POST https://core.newland-studio.com/auth/verify \
-H "Content-Type: application/json" \
-H "X-Tenant-Slug: your-tenant" \
-d '{"token":"eyJhbGci..."}'レスポンス (200 valid):
json
{ "valid": true, "userId": "01HX...", "tenantId": "...", "role": "member", "email": "..." }レスポンス (401 invalid):
json
{ "valid": false, "reason": "expired" }reason の値: malformed / expired / revoked
エラーレスポンス
| HTTP ステータス | 内容 |
|---|---|
| 400 | バリデーションエラー(必須フィールド欠如 / 形式不正) |
| 401 | 認証失敗(パスワード不一致 / トークン無効) |
| 404 | テナントまたはユーザーが見つからない |
| 409 | メールアドレス重複(同テナント内) |
トークン仕様
| 項目 | 値 |
|---|---|
| アルゴリズム | HS256 |
| アクセストークン有効期限 | 1時間 (3600秒) |
| セッション TTL (KV) | 1時間 |
| Issuer | https://core.newland-studio.com |
| Audience | newland-core |