Skip to main content

POST /api/v1/auth/login

Authenticate a user and receive a JWT access token.

Headers

X-Tenant
string
Tenant identifier for multi-tenant authentication. If not provided, uses legacy mode.
Content-Type
string
required
Must be application/x-www-form-urlencoded

Request Body (Form Data)

username
string
required
Username or email address. The system accepts both and searches case-insensitively.
password
string
required
User password (minimum 6 characters)
grant_type
string
OAuth2 grant type. Default: password
scope
string
OAuth2 scope (not currently used)

Response

access_token
string
required
JWT access token valid for 480 minutes (8 hours)
token_type
string
required
Token type, always returns "bearer"
user
object
required
User information object
curl -X POST "https://api.vigia.com/api/v1/auth/login" \
  -H "X-Tenant: acme-pharma" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "[email protected]" \
  -d "password=SecurePass123"
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjMiLCJ1aWQiOjEyMywidXNlcm5hbWUiOiJqdWFuLnBlcmV6IiwiZW1haWwiOiJqdWFuLnBlcmV6QGV4YW1wbGUuY29tIiwicm9sZSI6ImFkbWluIiwicm9sZXMiOlsiYWRtaW4iLCJxZiJdLCJ0ZW5hbnQiOiJhY21lLXBoYXJtYSIsInRyYWNlIjoiYWJjZDEyMzQiLCJleHAiOjE3MDk4NTYwMDB9.signature",
  "token_type": "bearer",
  "user": {
    "id": 123,
    "username": "juan.perez",
    "email": "[email protected]",
    "role": "admin",
    "roles": ["admin", "qf"]
  }
}

GET /api/v1/auth/me

Retrieve detailed information about the currently authenticated user.

Headers

Authorization
string
required
Bearer token obtained from login endpointFormat: Bearer <token>
X-Tenant
string
Tenant identifier (extracted from token if not provided)

Response

id
integer
required
User ID
email
string
required
User email address
username
string
required
Username
full_name
string
User’s full name
role
string
Primary role (admin prioritized)
roles
array
required
List of all assigned role names
permissions
object
required
Custom permissions object (module-specific permissions)
is_active
boolean
required
Whether the user account is active
empleado_id
integer
Associated employee ID from HR module
curl -X GET "https://api.vigia.com/api/v1/auth/me" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "X-Tenant: acme-pharma"
{
  "id": 123,
  "email": "[email protected]",
  "username": "juan.perez",
  "full_name": "Juan Pérez García",
  "role": "admin",
  "roles": ["admin", "qf"],
  "permissions": {
    "icsr": {
      "view": true,
      "edit": true,
      "delete": true
    },
    "reports": {
      "view": true,
      "generate": true
    }
  },
  "is_active": true,
  "empleado_id": 456
}

GET /api/v1/auth/whoami

Get basic information about the current user (lightweight version of /me).

Headers

Authorization
string
required
Bearer token

Response

id
integer
User ID
username
string
Username
full_name
string
User’s full name
email
string
User email address
role
string
Primary role (first role in list)
roles
array
List of assigned role names
empleado_id
integer
Employee ID reference
curl -X GET "https://api.vigia.com/api/v1/auth/whoami" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
{
  "id": 123,
  "username": "juan.perez",
  "email": "[email protected]",
  "full_name": "Juan Pérez García",
  "role": "admin",
  "roles": ["admin", "qf"],
  "empleado_id": 456
}

POST /api/v1/auth/change-password

Change the password for the currently authenticated user.

Headers

Authorization
string
required
Bearer token
Content-Type
string
required
Must be application/json

Request Body

current_password
string
required
Current password for verification
new_password
string
required
New password (minimum 6 characters)

Response

ok
boolean
required
Success indicator, always true on success
curl -X POST "https://api.vigia.com/api/v1/auth/change-password" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "current_password": "OldPassword123",
    "new_password": "NewSecurePass456"
  }'
{
  "ok": true
}

POST /api/v1/auth/reset-password

Reset a user’s password (admin/development endpoint).
This endpoint is intended for administrative use and development/testing. In production, this should be restricted to admin users only.

Headers

X-Tenant
string
required
Tenant identifier (required for this endpoint)
Content-Type
string
required
Must be application/json

Request Body

email
string
required
Email address of the user whose password should be reset
new_password
string
required
New password to set (minimum 6 characters)

Response

ok
boolean
required
Success indicator
email
string
required
Email of the user whose password was reset
tenant
string
required
Tenant where the operation was performed
curl -X POST "https://api.vigia.com/api/v1/auth/reset-password" \
  -H "X-Tenant: acme-pharma" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "new_password": "NewPassword123"
  }'
{
  "ok": true,
  "email": "[email protected]",
  "tenant": "acme-pharma"
}

Common Error Codes

All authentication endpoints may return these standard HTTP status codes:
Status CodeDescription
200Success
401Unauthorized (invalid credentials or token)
403Forbidden (inactive user or no roles)
404Not Found (user not found)
422Unprocessable Entity (validation error)
500Internal Server Error

Token Usage Example

After obtaining a token from the login endpoint, use it in all subsequent requests:
Complete Authentication Flow
import requests

# 1. Login
login_response = requests.post(
    "https://api.vigia.com/api/v1/auth/login",
    headers={"X-Tenant": "acme-pharma"},
    data={
        "username": "[email protected]",
        "password": "SecurePass123"
    }
)

token = login_response.json()["access_token"]

# 2. Use token for authenticated requests
headers = {
    "Authorization": f"Bearer {token}",
    "X-Tenant": "acme-pharma"
}

# 3. Get current user info
user_info = requests.get(
    "https://api.vigia.com/api/v1/auth/me",
    headers=headers
).json()

# 4. Make other API calls
icsrs = requests.get(
    "https://api.vigia.com/api/v1/icsrs",
    headers=headers
).json()

Build docs developers (and LLMs) love