Skip to main content

Authentication

RAG-DocBot uses JWT (JSON Web Token) based authentication with short-lived access tokens and longer-lived refresh tokens.


Token Lifetimes

TokenDefault Lifetime
Access token15 minutes (900 seconds)
Refresh token7 days (604800 seconds)

Public Endpoints

The following endpoints do not require authentication:

  • GET /api/health
  • GET /api/branding
  • GET /api/branding/logo

All other endpoints require a valid Bearer token in the Authorization header.


Auth Endpoints

EndpointDescription
POST /api/auth/loginExchange username + password for access and refresh tokens
POST /api/auth/refreshExchange a refresh token for a new access token
GET /api/auth/meGet the currently authenticated user
CRUD /api/auth/usersManage users (admin only)

Environment Variables

VariableDefaultDescription
JWT_SECRET_KEY(must be set)Secret key used to sign JWTs — change this before deployment
JWT_ALGORITHMHS256Signing algorithm
ACCESS_TOKEN_EXPIRE_SECONDS900Access token lifetime in seconds
REFRESH_TOKEN_EXPIRE_SECONDS604800Refresh token lifetime in seconds
DEFAULT_ADMIN_USERadminUsername for the default admin account
DEFAULT_ADMIN_PASSWORDchangemePassword for the default admin account
warning

The default admin account is created on first startup with the credentials in .env. Change DEFAULT_ADMIN_USER, DEFAULT_ADMIN_PASSWORD, and especially JWT_SECRET_KEY before exposing the service.


Example: Login and Call a Protected Endpoint

1. Log in and obtain tokens

curl -s -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "changeme"}'

Response:

{
"access_token": "<ACCESS_TOKEN>",
"refresh_token": "<REFRESH_TOKEN>",
"token_type": "bearer"
}

2. Call a protected endpoint

curl -s http://localhost:8000/api/docs \
-H "Authorization: Bearer <ACCESS_TOKEN>"

3. Refresh the access token

curl -s -X POST http://localhost:8000/api/auth/refresh \
-H "Content-Type: application/json" \
-d '{"refresh_token": "<REFRESH_TOKEN>"}'

4. Create a new user (admin only)

curl -s -X POST http://localhost:8000/api/auth/users \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"username": "alice", "password": "s3cure!", "role": "editor"}'