概要Overview

Face ID は「パスワードの後の 2 段階目」としてサインインに追加します。サイトのユーザー管理はそのままで、サイトのユーザー ID を Face ID に渡すだけです。Face ID is added as the second step after the password. Your site keeps its own user accounts and simply passes its user ID to Face ID.

Browser                    Your site's server                      Face ID
  │  password  ───────────▶  check password ✓
  │                          POST /v1/sessions {user_id,mode:"verify"} ──▶  session + url
  │  ◀── url ───────────────
  │  FaceID.open(url) ─── popup: passkey or camera face ─────────────────▶  verified
  │  "done" ────────────────▶ GET /v1/sessions/{id} ────────────────────▶  {"status":"verified"}  (once)
  │  ◀── signed in ──────────

1. サイトを登録する1. Register the site

サイトごとにクライアントを 1 つ作成します(管理者トークンが必要)。origins にはそのサイトの URL を入れてください。返ってくる secret は一度しか表示されません。サイトのサーバーの環境変数に保存し、ブラウザには絶対に出さないでください。Create one client per site (needs the admin token). Put the site’s URL in origins. The returned secret is shown once: store it in the site server’s environment and never send it to the browser.

curl -X POST https://faceid.ai-sns.io/admin/clients \
  -H "Authorization: Bearer $FACEID_ADMIN_TOKEN" -H "content-type: application/json" \
  -d '{"name":"AI SNS CHAT","origins":["https://chatapp.ai-sns.io"]}'
# → {"client_id":"fc_…","secret":"fid_sk_…"}

2. 登録(ユーザーが Face ID を設定)2. Enrolment (the user turns Face ID on)

アカウント設定画面に「Face ID を設定」ボタンを置きます。ログイン済みのユーザーにだけ表示してください。Put a “Set up Face ID” button on the account settings page, shown only to a signed-in user.

// server
const FACEID = 'https://faceid.ai-sns.io';
const H = { 'Authorization': `Bearer ${process.env.FACEID_SECRET}`, 'content-type': 'application/json' };

app.post('/account/faceid/start', requireLogin, async (req, res) => {
  const r = await fetch(`${FACEID}/v1/sessions`, { method: 'POST', headers: H,
    body: JSON.stringify({ user_id: String(req.user.id), mode: 'enroll' }) });
  const s = await r.json();
  req.session.faceid = s.session_id;          // remember which session belongs to this user
  res.json({ url: s.url });
});

app.post('/account/faceid/finish', requireLogin, async (req, res) => {
  const v = await (await fetch(`${FACEID}/v1/sessions/${req.session.faceid}`, { headers: H })).json();
  res.json({ enabled: v.status === 'verified' && v.user_id === String(req.user.id) });
});

ブラウザ側(全言語共通)Browser (same for every stack)

<script src="https://faceid.ai-sns.io/sdk.js"></script>
<button id="faceid-setup"></button>
<script>
FaceID.button(document.getElementById('faceid-setup'), { label: 'Face ID を設定', onClick: async () => {
  const { url } = await (await fetch('/account/faceid/start', { method: 'POST' })).json();
  await FaceID.open(url);                                   // popup
  const r = await (await fetch('/account/faceid/finish', { method: 'POST' })).json();
  alertBox(r.enabled ? 'Face ID を有効にしました' : '設定されませんでした');
}});
</script>

3. サインイン(パスワードの後に顔で確認)3. Sign-in (face after the password)

パスワードが正しければ、まだログインさせずに「確認待ち」状態にします。Face ID を設定済みのユーザーなら確認セッションを作り、確定してからログインさせます。When the password is right, don’t sign the user in yet: hold them in a “pending” state. If they have Face ID on, open a verify session and sign them in only once it is confirmed.

// server (Node)
app.post('/login', async (req, res) => {
  const user = await checkPassword(req.body.email, req.body.password);
  if (!user) return res.status(401).json({ error: 'bad credentials' });

  const st = await (await fetch(`${FACEID}/v1/users/${encodeURIComponent(user.id)}`, { headers: H })).json();
  if (!st.enrolled) { startSession(req, user); return res.json({ ok: true }); }   // Face ID off: as before

  const s = await (await fetch(`${FACEID}/v1/sessions`, { method: 'POST', headers: H,
    body: JSON.stringify({ user_id: String(user.id), mode: 'verify' }) })).json();
  req.session.pending = { userId: user.id, faceid: s.session_id, at: Date.now() };
  res.json({ faceid: s.url });                                  // browser opens the popup
});

app.post('/login/faceid', async (req, res) => {
  const p = req.session.pending;
  if (!p || Date.now() - p.at > 5 * 60e3) return res.status(401).json({ error: 'expired' });
  const v = await (await fetch(`${FACEID}/v1/sessions/${p.faceid}`, { headers: H })).json();
  delete req.session.pending;
  if (v.status !== 'verified' || v.user_id !== String(p.userId)) return res.status(401).json({ error: 'face not confirmed' });
  startSession(req, await getUser(p.userId));
  res.json({ ok: true });
});

// browser
const r = await (await fetch('/login', { method: 'POST', body: form })).json();
if (r.faceid) { await FaceID.open(r.faceid); await fetch('/login/faceid', { method: 'POST' }); }

API リファレンスAPI reference

すべて Authorization: Bearer fid_sk_…(サイトのシークレット)が必要です。All calls take Authorization: Bearer fid_sk_… (the site’s secret).

Endpoint内容What it does
POST /v1/sessions{user_id, mode:"enroll"|"verify", methods?:["passkey","face"], return_url?, locale?} → {session_id, url, expires_at}. 未登録ユーザーの verify は 409 not_enrolled、ロック中は 423。Verify for a user with nothing enrolled returns 409 not_enrolled; a locked user returns 423.
GET /v1/sessions/{id}{status, user_id, mode, method, score}. status: pending · verified · consumed · failed · cancelled · expired. verified は最初の 1 回だけ返り、以降は consumed。“verified” is returned on the first read only; later reads say consumed.
GET /v1/users/{user_id}{enrolled, face, passkey, passkeys, locked}
DELETE /v1/users/{user_id}顔データ・パスキーをすべて削除(退会・設定オフ時に呼ぶ)Erase every face template and passkey (call on account deletion or when the user turns Face ID off)

ポップアップが使えない場合(アプリ内ブラウザなど)When popups are blocked (in-app browsers)

return_url(登録済み origin 内)を渡すと、確認後に ?faceid_session=fs_… 付きでサイトに戻ります。サーバーでそのセッションを読んでください。Pass a return_url (inside a registered origin). After the check the user comes back with ?faceid_session=fs_…; read that session on the server.

必ず守ることRules that keep it secure

  • ポップアップの結果だけでログインさせない。必ずサーバーで GET /v1/sessions/{id} を読み、status === "verified" と user_id の一致を確認する。Never sign anyone in on the popup message alone. Always read GET /v1/sessions/{id} on the server and check status === "verified" and that user_id matches.
  • セッション ID はサーバー側のセッションに保存する(ブラウザから受け取った ID を信用しない)。Keep the session ID in your server-side session; don’t trust an ID the browser sends you.
  • enroll はログイン済みユーザーにのみ。すでに Face ID がある場合は、先に verify を通してから追加させる。Open enroll only for a signed-in user. If they already have Face ID, make them pass verify first.
  • fid_sk_ シークレットはサーバーの環境変数のみ。漏れたら管理 API で rotate_secret。Keep the fid_sk_ secret in server env only. If it leaks, call rotate_secret on the admin API.
  • 退会時は DELETE /v1/users/{id} を呼ぶ(個人情報保護法上の削除義務)。Call DELETE /v1/users/{id} when an account is deleted (data-protection erasure duty).