How authentication works
The Mesa de Ayuda API uses JWT (JSON Web Tokens) with the Bearer scheme. After you log in viaPOST /api/auth/login, you receive a signed token. Include that token in the Authorization header of every subsequent request.
Tokens are signed using HMAC-SHA256 (HS256 by default) with a server-side secret key. The server validates the signature and expiry on every request — no session state is stored.
Obtaining a token
Send your email and password to the login endpoint:Including the token in requests
Pass the token as a Bearer token in theAuthorization header:
Token expiry
Tokens expire after 120 minutes by default. You can change this by settingACCESS_TOKEN_EXPIRE_MINUTES in your .env file:
.env
iat (issued at) and exp (expiry) claim as UTC Unix timestamps. Once expired, the token is rejected and you must log in again to obtain a new one.
The API does not currently support token refresh. When your token expires, call
POST /api/auth/login again with your credentials.Roles and permissions
Every user has arol field embedded in their JWT payload. The API uses this role to authorize access to specific endpoints.
| Role | Description |
|---|---|
ADMIN | Full access to all endpoints. Manages users, tickets, and system configuration. |
MESA | Help desk staff. Can view, assign, and update all tickets. |
AREA | Area supervisor. Can view and manage tickets assigned to their area. |
USUARIO | Ticket requester. Uses the public endpoints (/crear, /consultar) without authentication — no JWT token required. |
require_roles dependency in app/core/deps.py. Endpoints declare which roles are allowed, and the server rejects requests from users with insufficient privileges.
Error responses
401 — Invalid or expired token
You receive a401 response when:
- The
Authorizationheader is missing - The token signature is invalid
- The token has expired
POST /api/auth/login to obtain a fresh token.
403 — Insufficient role
You receive a403 response when your token is valid but your role does not have permission to access the endpoint: