|
MantisBase v0.3.4
|
MantisBase provides standalone authentication endpoints for user login, token refresh, and logout. These endpoints are separate from entity endpoints and handle JWT token management.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/login | Authenticate user and get token |
| POST | /api/v1/auth/refresh | Refresh an existing token |
| POST | /api/v1/auth/logout | Logout (invalidate token) |
| POST | /api/v1/auth/setup/admin | Create initial admin account |
Authenticate a user and receive a JWT token.
⚠️ Rate Limiting: This endpoint is rate-limited to 5 attempts per minute per IP address to prevent brute force attacks. If you exceed this limit, you'll receive a
429 Too Many Requestsresponse with aRetry-Afterheader indicating when you can try again.
Endpoint: POST /api/v1/auth/login
Request Body:
Request Fields:
entity (required): The entity/table name where the user account exists (e.g., "users", "mb_admins")identity (required): User identifier - can be either an email address or user IDpassword (required): User's passwordResponse (Success - 200):
Response (Error - 404):
Response (Rate Limited - 429):
The rate limit response includes these headers:
X-RateLimit-Limit: Maximum requests allowed (5)X-RateLimit-Remaining: Remaining requests in window (0 when rate limited)X-RateLimit-Reset: Unix timestamp when the window resetsRetry-After: Seconds to wait before retryingExamples:
Login with email:
Login with user ID:
Refresh an existing JWT token to extend its validity.
Endpoint: POST /api/v1/auth/refresh
Request Headers:
Response (Success - 200):
Example:
Logout and invalidate the current token.
Endpoint: POST /api/v1/auth/logout
Request Headers:
Response (Success - 200):
Example:
Create the initial admin account. This endpoint is typically used during first-time setup when no admin accounts exist. This is called by the system, do not use it.
Endpoint: POST /api/v1/auth/setup/admin
Request Body:
Response (Success - 200):
Example:
⚠️ Note: This endpoint is only available when no admin accounts exist. Once an admin is created, use the regular login endpoint or create additional admins via the CLI:
mantisbase admins --add <email>
After receiving a token from the login endpoint, include it in all subsequent API requests:
The token contains user information (id, entity) and is validated automatically by the getAuthToken() middleware on all endpoints.
By default, tokens expire after 1 hour. Use the refresh endpoint to extend token validity without requiring the user to log in again.
The authentication API provides secure user authentication with JWT tokens. Tokens are automatically validated on all entity endpoints, ensuring only authenticated users can access protected resources.