Skip to main content
The Authentication API provides endpoints for user registration, login, logout, token management, and OAuth integration. Base Path: /api/auth/v1

Register User

Register a new user with email and password.
POST /api/auth/v1/register

Request Body

string
required
User’s email address (will be normalized to lowercase)
string
required
User’s password (must meet password policy requirements)
string
required
Password confirmation (must match password)

Response

See Other
Success redirect to login page with confirmation message
Temporary Redirect
Invalid password, redirects back to registration
Forbidden
Password authentication is disabled
Failed Dependency
Failed to send verification email
If a user with the email already exists, TrailBase returns success to prevent email enumeration attacks.

Login

Authenticate users with email and password.
POST /api/auth/v1/login

Request Body

string
required
User’s email address
string
required
User’s password
string
Optional redirect URL after successful login (for web flows)
string
Set to "code" to use Authorization Code Flow with PKCE
string
PKCE code challenge (required when using Authorization Code Flow)

Response (JSON)

string
Short-lived JWT authentication token (default: 60 minutes)
string
Long-lived refresh token (default: 30 days)
string
CSRF token for state-changing operations

Response (Form/Cookie)

For form submissions, sets auth_token and refresh_token cookies and redirects.

Authorization Code Flow with PKCE

For native/mobile apps that cannot securely store tokens:

Refresh Token

Obtain a new auth token using a refresh token.
POST /api/auth/v1/refresh

Request Body

string
required
Valid refresh token from login response

Response

string
New short-lived JWT authentication token
string
New CSRF token
Refresh tokens are single-use. Each refresh returns a new auth token and the refresh token is rotated.

Logout

Log out the current user and delete their session(s).

Logout (GET) - All Sessions

GET /api/auth/v1/logout
string
Optional URL to redirect to after logout
Deletes all sessions for the current user and clears cookies.

Logout (POST) - Specific Session

POST /api/auth/v1/logout
string
required
Refresh token for the specific session to delete
Deletes only the session associated with the provided refresh token.

Login Status

Check current authentication status.
GET /api/auth/v1/status

Response

Exchange Authorization Code

Exchange authorization code for auth tokens (OAuth-style flow).
POST /api/auth/v1/token

Request Body

string
required
Authorization code received from redirect (24 characters)
string
required
PKCE code verifier matching the challenge from login request

Response

Authorization codes are single-use and expire after 5 minutes.

OAuth Integration

List OAuth Providers

Get configured OAuth providers.
GET /api/auth/v1/oauth/providers

Response

OAuth Login

Initiate OAuth login flow with external provider.
GET /api/auth/v1/oauth/{provider}/login
string
required
OAuth provider name (google, github, microsoft, discord, etc.)
string
Callback URL after successful authentication
string
Set to "code" for Authorization Code Flow
string
PKCE code challenge for Authorization Code Flow
Redirects to the OAuth provider’s authorization page.

OAuth Callback

Handles the callback from OAuth provider.
GET /api/auth/v1/oauth/{provider}/callback
string
required
Authorization code from OAuth provider
string
required
CSRF state token for validation

Email Verification

Request Email Verification

GET /api/auth/v1/verify_email/trigger

Verify Email

GET /api/auth/v1/verify_email/confirm/{code}

Password Management

Change Password

POST /api/auth/v1/change_password

Request Password Reset

POST /api/auth/v1/reset_password/request

Reset Password

POST /api/auth/v1/reset_password/update

User Management

Delete User Account

DELETE /api/auth/v1/delete
Deletes the authenticated user’s account and all associated data.

Avatar Management

Get User Avatar

GET /api/auth/v1/avatar/{user_id}
Returns the user’s avatar image file.

Upload Avatar

POST /api/auth/v1/avatar

Delete Avatar

DELETE /api/auth/v1/avatar

Error Responses

Unauthorized
Invalid credentials, expired token, or authentication required
Forbidden
Password authentication disabled or email not verified
Conflict
User already exists (only in debug mode)
Too Many Requests
Rate limit exceeded (password reset, email verification)

Password Policy

Password requirements can be configured via TrailBase settings. Default policy:
  • Minimum length: 8 characters
  • Must contain uppercase, lowercase, digit, and special character
  • Cannot be a common password

Token Lifetimes

  • Auth Token: 60 minutes (configurable, 2 minutes in debug mode)
  • Refresh Token: 30 days (configurable)
  • Authorization Code: 5 minutes
  • Email Verification Code: Varies by configuration
  • Password Reset Code: Varies by configuration