Skip to content

API 利用ガイド

newland-core は Cloudflare Workers 上で動作するマルチテナント対応の認証 API です。 全てのエンドポイントに X-Tenant-Slug ヘッダーを付与して呼び出します。

エンドポイント一覧

メソッドパス認証概要
POST/auth/register不要ユーザー登録
POST/auth/login不要ログイン・トークン発行
POST/auth/logoutBearerセッション無効化
GET/auth/meBearerプロフィール取得
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時間
Issuerhttps://core.newland-studio.com
Audiencenewland-core

newland-studio/newland-core