メインコンテンツへ
BlueAI
ホーム/ガイド/認証

認証

BlueAI API への認証方法。

|

概要

BlueAI API は Better Auth と互換性のあるセッションベースの認証を使用します。サインイン後、すべてのリクエストにセッション Cookie を含めてください。

セッション Cookie

サインイン成功後、API は POST /api/v1/auth/sign-in/email, Cookie を設定します。 better-auth.session_token cookie.

# Sign in
curl -X POST https://api.blueai.jp/api/v1/auth/sign-in/email \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"secret"}' \
  -c cookies.txt

# Use the session cookie
curl https://api.blueai.jp/api/v1/me \
  -b cookies.txt

ブラウザリクエスト

ブラウザの JavaScript からは、fetch の呼び出しに credentials: "include" を含めることで、セッション Cookie が自動的に送信されます。

const res = await fetch("https://api.blueai.jp/api/v1/me", {
  credentials: "include",
});
const data = await res.json();

組織コンテキスト

ほとんどの API エンドポイントは組織コンテキスト内で動作します。ユーザーの現在の組織はセッションから判定されます。組織を切り替えるには、組織選択エンドポイントを使用してください。