IAI Flow dùng cookie-based session auth. Không có API keys, không có Bearer tokens trong header. Session được gửi tự động qua HttpOnly cookie.
Gửi email + password. Nhận Set-Cookie: iai_session=... trong response.
Browser tự gửi cookie. Không cần attach token thủ công.
Kiểm tra session còn hiệu lực. Dùng trên mọi page load của dash.iai.one.
Logout. Xóa session trong D1. Cookie bị clear.
{
"email": "you@company.com",
"password": "your-password"
}
Set-Cookie: iai_session=<opaque-token>; HttpOnly; Secure; SameSite=None; Path=/; Max-Age=604800
{
"authenticated": true,
"user": {
"id": "usr_abc123",
"email": "you@company.com",
"name": "Your Name"
},
"workspace": {
"workspaceId": "ws_xyz",
"name": "My Workspace",
"role": "owner"
}
}
{ "error": "Invalid credentials" }
{
"authenticated": true,
"user": { "id": "usr_...", "email": "...", "name": "..." },
"workspace": { "workspaceId": "ws_...", "name": "...", "role": "owner" }
}
{ "authenticated": false }
{ "ok": true }
Cookie bị clear, session bị xóa khỏi D1.
| Property | Value |
|---|---|
| Cookie name | iai_session |
| TTL | 7 ngày (604800 giây) |
| Storage | D1 database (opaque token) |
| Password hash | PBKDF2-SHA256, 100k iterations |
| SameSite | None (required for cross-origin dash.iai.one) |
| Secure | true (HTTPS only) |
| HttpOnly | true (không accessible bởi JS) |
SameSite=None; Secure. Và client phải gửi credentials: "include" với mọi fetch.
// auth-guard.js — runs on every protected page
async function checkSession() {
const res = await fetch("https://api.flow.iai.one/api/auth/session", {
credentials: "include"
});
if (res.status !== 200) {
location.replace("/login/?next=" +
encodeURIComponent(location.pathname));
return null;
}
const data = await res.json();
if (!data.authenticated) {
location.replace("/login/");
return null;
}
return data; // { user, workspace }
}
API returns these headers for dash.iai.one and developer.iai.one origins:
Access-Control-Allow-Origin: https://dash.iai.one
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
*.iai.one được allow. Mọi subdomain của iai.one có thể gọi API với credentials.