fastcheck/fastcheck_api/docs/authentication.md
2026-04-16 12:05:29 -04:00

1.4 KiB

Authentication

FastCheck uses bearer JWT authentication.

Source of truth

Authentication is compatible with the existing Node.js backend:

  • Users are stored in the existing users collection.
  • Passwords are verified against the existing bcrypt hash in users.password.
  • Tenant membership is read from users.tenant.
  • Access control is enforced using users.role (role → permissions mapping in code).

Obtain a token

cURL

curl -sS -X POST "http://127.0.0.1:8080/api/v1/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"********"}'

Python (httpx)

import httpx

resp = httpx.post(
    "http://127.0.0.1:8080/api/v1/auth/login",
    json={"email": "user@example.com", "password": "********"},
)
resp.raise_for_status()
token = resp.json()["token"]

JavaScript (fetch)

const resp = await fetch("http://127.0.0.1:8080/api/v1/auth/login", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email: "user@example.com", password: "********" }),
});
if (!resp.ok) throw new Error(await resp.text());
const { token } = await resp.json();

Use the token

Send it as:

Authorization: Bearer <jwt>

Token refresh

curl -sS -X POST "http://127.0.0.1:8080/api/v1/auth/refresh" \
  -H "Authorization: Bearer <jwt>"