![]() |
MantisBase v0.4.9
|
MantisBase provides authentication endpoints scoped to auth-type entities. Each auth entity exposes login, refresh, and logout under /api/v1/auth/<entity>/. A global token verification endpoint is available at /api/v1/auth/verify.
Admin authentication uses /api/v1/sys/admins/ instead.
| Code | Meaning |
|---|---|
| 401 Unauthorized | Missing, invalid, or expired credentials |
| 403 Forbidden | Authenticated, but not allowed to perform the action (for example, a regular user token on an admin-only route) |
<entity> must be a registered entity that is:
If the entity is missing or does not meet these requirements, the route returns 404 Route Not Found.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/auth/verify | Check whether the current JWT or API key is still valid |
| POST | /api/v1/auth/<entity>/login | Authenticate user and get token |
| POST | /api/v1/auth/<entity>/otp/request | Email a one-time sign-in code |
| POST | /api/v1/auth/<entity>/otp/login | Sign in with an emailed code |
| POST | /api/v1/auth/<entity>/verify-email/request | Email an address-verification link |
| POST | /api/v1/auth/<entity>/verify-email | Confirm an address with the link token |
| GET | /api/v1/auth/<entity>/verify-email?token= | Confirm an address from the email link |
| POST | /api/v1/auth/<entity>/password-reset/request | Email a password-reset link |
| POST | /api/v1/auth/<entity>/password-reset | Set a new password with the link token |
| GET | /api/v1/auth/<entity>/password-reset?token= | HTML form to choose a new password |
| POST | /api/v1/auth/<entity>/refresh | Refresh an existing token |
| POST | /api/v1/auth/<entity>/logout | Logout (invalidate token) |
For admin authentication and initial setup, see System Endpoints – Admin Accounts (/api/v1/sys/admins/).
Each auth entity has three login methods. Password login is enabled by default. Email sign-in codes and OAuth are disabled until an admin enables them. Login routes return 403 while a method is disabled.
| Method | Schema field | Default | Routes |
|---|---|---|---|
| Email and password | auth.password | true | POST /api/v1/auth/<entity>/login |
| Email sign-in code | auth.otp | false | POST /api/v1/auth/<entity>/otp/request and /otp/login |
| OAuth | auth.oauth | false | /api/v1/auth/<entity>/oauth/authorize, /callback, /link, /providers |
| Require a verified email | auth.requireEmailVerification | false | Password, OTP, and OAuth login |
Read the current flags without an admin token:
Change them with an admin token. Schema routes are admin-only. A patch merges the fields you send, so the example below turns on OTP and leaves password and OAuth as they are:
Existing sessions keep working after a method is turned off. New logins for that method are rejected.
When requireEmailVerification is true, password login, email-code login, and OAuth login return 403 Verify your email before signing in. until email_verified is true. Sessions that are already signed in keep working. The flag defaults to false, so existing deployments keep the current login behavior until an admin turns it on.
Auth tables store a system field email_verified (boolean, default false). New auth entities include it. Tables created before this field existed gain the column on startup; existing rows are unverified. Admin accounts (mb_admins) do not have the field.
Clients cannot set email_verified on create or update. An admin can set it with PATCH /api/v1/entities/<entity>/<id>. Changing the account email clears the flag unless that same admin request sets it.
When SMTP is configured, creating an account emails a verification link. The link is {siteDomain}/api/v1/auth/<entity>/verify-email?token=..., expires after 24 hours, and works once. Set siteDomain so the link points at this server. If SMTP is not configured, registration still succeeds and no message is sent.
Request another link:
The response is the same when no account uses that email, and no message is sent. An address that is already verified also returns sent: true without a new message. SMTP must be configured, otherwise the response is 400 Email service not configured. Set SMTP settings first.
Opening the link in a browser returns a short HTML page. A client can confirm the same token with JSON:
A missing, used, or expired token returns 400 Invalid or expired verification link.
OAuth login marks email_verified when the provider asserts email_verified. Otherwise, and when SMTP is configured, a verification link is sent for that account.
Request a reset link for an account email. SMTP and siteDomain are required. The link is {siteDomain}/api/v1/auth/<entity>/password-reset?token=..., expires after 1 hour, and works once.
The response is the same when no account uses that email, and no message is sent. Opening the link in a browser shows a form to choose a new password. A client can also complete the reset with JSON:
Passwords must be at least 8 characters with no whitespace. A successful reset invalidates existing sessions for that account. A missing, used, or expired token returns 400 Invalid or expired password reset link.
Authenticate a user and receive a JWT token.
⚠️ Rate Limiting: Login 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 Requests response with a Retry-After header indicating when you can try again.
Endpoint: POST /api/v1/auth/<entity>/login
Request Body:
Request Fields:
The target entity is taken from the URL path, not the request body.
Response (Success - 200):
Response (Error - 404):
Response (Rate Limited - 429):
The rate limit response includes these headers:
Examples:
Login with email:
Login with user ID:
Sign in with an email address and a one-time code. No password is required. This also works for accounts that have no password, such as OAuth-only users.
An admin must set auth.otp to true on the entity first. Until then the OTP routes return 403.
SMTP must already be configured under application settings. If it is not, the request returns 400:
The code is 6 digits, expires after 10 minutes, and allows 5 attempts. Requesting a new code replaces the previous one after the email is sent. Each code can be used once.
⚠️ Rate limiting: Both OTP routes use the same limit as password login (5 attempts per minute per IP). Outbound mail is also limited to 3 messages per hour for each recipient.
Endpoint: POST /api/v1/auth/<entity>/otp/request
Request Body:
Response (Success - 200):
The response is the same when no account uses that email, and no message is sent in that case. Delivery errors are returned only when a message was attempted.
Example:
Endpoint: POST /api/v1/auth/<entity>/otp/login
Request Body:
Response (Success - 200): Same shape as password login: data.token, data.user, and an HttpOnly mb_token cookie.
Response (Error - 401):
A code that is not 6 digits returns 400 with "Sign-in code must be a 6-digit number."
Example:
Refresh an existing JWT token to extend its validity.
Endpoint: POST /api/v1/auth/<entity>/refresh
Request Headers:
Response (Success - 200):
Example:
Logout and invalidate the current token.
Endpoint: POST /api/v1/auth/<entity>/logout
Request Headers:
Response (Success - 200):
Example:
Check whether the current JWT or API key is still valid without performing a refresh or logout. Useful for client-side session checks and keeping UI auth state in sync.
⚠️ Rate Limiting: Verify is rate-limited to 5 requests per minute per IP address. If you exceed this limit, you'll receive a 429 Too Many Requests response.
Endpoint: GET /api/v1/auth/verify
This route is not entity-scoped. It accepts any valid entity user JWT or mb_sk_... API key via the standard Authorization header.
Request Headers:
Response (Success - 200):
Response (Missing token - 401):
Response (Invalid or expired token - 401):
The error field may contain a more specific message when token verification fails (for example, an expired JWT).
Examples:
Verify a JWT:
Verify an API key:
Admin account setup and admin-only authentication use the /api/v1/sys/admins/ namespace. See System Endpoints – Admin Accounts in the API reference.
Initial setup: POST /api/v1/sys/admins/setup (only when no admin accounts exist)
Admin login: POST /api/v1/sys/admins/login
After receiving a token from the login endpoint, include it in all subsequent API requests:
JWTs and API keys both use the same header. API keys are prefixed with mb_sk_ and are validated by the same auth middleware as JWTs.
The token contains user information (id, entity) and is validated automatically by the getAuthToken() middleware on all endpoints.
Long-lived API keys complement short-lived JWTs. Keys are scoped to an auth entity and user, stored hashed server-side, and shown once at creation.
Send the raw key in the standard Authorization header:
The middleware resolves the key, hydrates the user record, and sets the same auth / verification request attributes as a JWT login.
Requires an authenticated session for the same auth entity (JWT from login).
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/<entity>/api-keys | Create a key (returns one-time key) |
| GET | /api/v1/auth/<entity>/api-keys | List keys (metadata only) |
| DELETE | /api/v1/auth/<entity>/api-keys/:id | Revoke a key |
Create request body:
Example:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/sys/api-keys | Create admin API key |
| GET | /api/v1/sys/api-keys | List admin keys |
| DELETE | /api/v1/sys/api-keys/:id | Revoke admin key |
Admin routes require admin JWT authentication.
OAuth 2.0 / OIDC login and account linking for auth-type entities. Preset providers (google, github, discord, microsoft) are seeded at startup; admins configure client credentials and enable providers per entity.
OAuth requires a dedicated encryption key for client secrets at rest:
| Variable | Required | Description |
|---|---|---|
| MB_OAUTH_ENCRYPTION_KEY | Yes, when OAuth is used | At least 32 characters. Encrypts provider client secrets in the database. Does not fall back to MB_JWT_SECRET. |
Set this in your environment or .env before enabling OAuth providers. See Docker Guide.
On callback, MantisBase exchanges the authorization code and verifies the provider ID token signature via the provider JWKS before trusting claims (sub, email, etc.).
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/auth/<entity>/oauth/authorize/:provider | Redirect to provider (PKCE) |
| GET | /api/v1/auth/<entity>/oauth/callback/:provider | OAuth callback; returns JWT on success |
| POST | /api/v1/auth/<entity>/oauth/link/:provider | Link provider to logged-in user |
| DELETE | /api/v1/auth/<entity>/oauth/link/:provider | Unlink provider |
| GET | /api/v1/auth/<entity>/oauth/accounts | List linked accounts |
| GET | /api/v1/auth/<entity>/oauth/providers | Providers enabled for entity |
Start login (browser redirect):
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/sys/oauth/providers | Add provider (name, client_id, client_secret) |
| GET | /api/v1/sys/oauth/providers | List providers |
| PATCH | /api/v1/sys/oauth/providers/:id | Update provider |
| DELETE | /api/v1/sys/oauth/providers/:id | Remove provider |
| POST | /api/v1/sys/oauth/entity-config | Enable provider for entity |
| DELETE | /api/v1/sys/oauth/entity-config | Disable provider for entity |
Enable provider for an entity:
By default, tokens expire after 1 hour. Use the refresh endpoint to extend token validity without requiring the user to log in again.
After authentication middleware runs, each request carries an auth object:
| Field | Values | Description |
|---|---|---|
| type | guest, user, admin | Role derived from the auth entity (mb_admins → admin) |
| mode | none, api, jwt | How the credential was presented |
| entity | string | MbAuth entity table name |
| id | string | Authenticated user id |
| user | object | Hydrated user record (password omitted) |
Admin users (type: admin) short-circuit all entity access rules. See Access Rules for rule modes and the optional entity filter on auth mode.
The authentication API provides JWT login (password or email one-time code), token verification (GET /api/v1/auth/verify), long-lived API keys (mb_sk_...), and OAuth for auth-type entities. All credential types use Authorization: Bearer ... and are validated before entity access rules run. Admin-only routes under /api/v1/sys/ manage providers and system API keys.