Authentication
Authula serves every auth endpoint under /v1/auth and issues the JWT pairs the rest of the API accepts.
Authentication is handled by Authula, wired in
cmd/api/authula.go and mounted with the Fiber adapter at /v1/auth.
Plugins
| Plugin | Configuration |
|---|---|
jwt | Access tokens 15 minutes, refresh tokens 7 days. |
bearer | Validates Authorization: Bearer <jwt> on API routes. |
session | HttpOnly session cookie (__Host-authula.session_token outside dev) used to exchange OAuth2/OIDC redirects for JWTs at POST /v1/auth/token. |
email | Resend, from RESEND_FROM_EMAIL. |
email-password | Passwords 8–128 chars, email verification required, auto sign-in, verification and reset emails from templates/emails. |
magic-link | Links valid 15 minutes. |
oauth2 | Google (GOOGLE_CLIENT_ID/SECRET) and generic OIDC (OIDC_ISSUER/CLIENT_ID/CLIENT_SECRET via discovery); scopes openid email profile. |
A response hook adds expires_in / expires_at to every token-issuing response so
clients can refresh proactively.
Endpoints
| Endpoint | Auth | Returns |
|---|---|---|
POST /v1/auth/email-password/sign-up | optional | Token pair |
POST /v1/auth/email-password/sign-in | optional | Token pair |
GET /v1/auth/email-password/verify-email | optional | |
POST /v1/auth/email-password/send-email-verification | bearer | |
POST /v1/auth/email-password/request-password-reset | bearer | |
POST /v1/auth/email-password/change-password | bearer | |
POST /v1/auth/email-password/request-email-change | bearer | |
POST /v1/auth/magic-link/sign-in | optional | Sends the email |
GET /v1/auth/magic-link/verify | optional | Redirects to callback_url?token=… |
POST /v1/auth/magic-link/exchange | optional | Token pair |
GET /v1/auth/providers | public | Enabled sign-in methods & Turnstile |
POST /v1/auth/token | session | Token pair (from OAuth2/OIDC cookie) |
GET /v1/auth/oauth2/authorize/google | optional | Redirect to Google |
GET /v1/auth/oauth2/callback/google | optional | Redirect to redirect_to |
GET /v1/auth/oauth2/authorize/oidc | optional | Redirect to OIDC provider |
GET /v1/auth/oauth2/callback/oidc | optional | Redirect to redirect_to |
POST /v1/auth/token/refresh | — | Rotated token pair |
GET /v1/auth/me | bearer | Authula user |
POST /v1/auth/sign-out | bearer |
"Token pair" is { access_token, refresh_token, token_type, expires_in, expires_at }
(the sign-in routes run jwt.respond_json). redirect_to and callback_url are checked
against the trusted origins (CORS_ALLOWED_ORIGINS).
Users in two schemas
Authula owns its tables in the authula schema. A service hook (syncUserToApp) upserts
every created or updated Authula user into public.users, splitting the display name into
first and last name and reading the global role from user metadata (default user).
Application handlers only read public.users.
GET /v1/me (an application route, not Authula's) returns that application user; the
frontend uses it as its session probe.
The super user
With SUPER_USER=email:password, every boot makes sure that account exists, is verified,
carries role=super_user, and has a password credential. The password is set only on creation,
so changing it later survives restarts.
Protecting application routes
middlewares.Authorization() (in internal/middlewares/authorization.go) reads the bearer
token, validates it through Authula's JWT service, and stores the user id in the request
context; handlers read it with currentUser(c). A missing or invalid token answers:
{ "message": "Unauthorized, invalid bearer token" }