Skip to content

Authentication ​

MethodPathDescription
POST/auth/registerRegister a regular user (email verification code required)
POST/auth/register/codeSend a registration verification code to an email address (no login required)
POST/auth/loginRegular user login (username or email)
POST/admin/auth/loginAdministrator login (separate entry point)
POST/auth/totp/verifyComplete TOTP two-factor verification during login (challenge_token + code)
GET/auth/meCurrent account information
GET/auth/securitySecurity settings status of the current account (TOTP, email)
POST/auth/totp/setupGenerate a TOTP secret and return the secret and otpauth link
POST/auth/totp/enableEnable two-factor authentication after verifying the dynamic code
POST/auth/totp/disableDisable two-factor authentication (dynamic code or password)
POST/auth/email/codeSend a verification code to the target email address (1 per minute, 10 per day per account)
POST/auth/email/verifyVerify the code and bind the email address; changing to a different email requires the current password
POST/auth/email/unbindUnbind the email address (current password required)
POST/auth/passwordChange the current account password (requires current_password, new_password)
POST/auth/password/reset/codeSend a password reset code to the verified email address (no login required)
POST/auth/password/resetVerify the code and reset the password (no login required)

Once TOTP is enabled, /auth/login and /admin/auth/login no longer return a session directly; instead they return {"totp_required": true, "challenge_token": "…"}. The client must call /auth/totp/verify with this token and the 6-digit code generated by the authenticator app to exchange it for a full session. TOTP secrets are encrypted with the master key before being stored, and login challenge tokens have their own scope and cannot be used as sessions. Email binding proves the address is actually reachable via the verification code; when no real mail channel is configured, codes fall back to being written to the server log.

Both regular users and administrators can use the security features above.

Email rebinding policy: binding and rebinding share the same send/verify endpoints. Rebinding only needs to verify the new email address, but when the target address differs from the currently verified one, the current password must be provided. After a successful rebind, a change notification is sent to the old address. Verification code sending is rate-limited per account (1 per minute, a burst of 2, and a maximum of 10 per day); exceeding the limit returns HTTP 429. Codes are valid for 10 minutes, are single-use, allow at most 5 attempts, and return HTTP 409 when they conflict with an address already bound to another account. Codes and daily send counters are persisted in the database, so they stay consistent across service restarts and multi-instance deployments.

Password management: a signed-in user can change their password by supplying the current password to POST /auth/password. If the password is forgotten, call POST /auth/password/reset/code to send a code to the verified email address, then call POST /auth/password/reset with the code to set a new password. To prevent account enumeration, requests for unregistered addresses also return success without actually sending mail, and during reset an unregistered address and an incorrect code return the same error.

Registration and email login: to register a regular user, first call POST /auth/register/code to send a verification code to the email address (returns HTTP 409 if the address is already taken), then call POST /auth/register with username, email, code, and password to complete registration. After successful registration the address is marked as verified. When logging in, the username field of POST /auth/login accepts either a username or an email address. Administrator accounts are created from the admin console or bootstrap configuration and do not go through this registration flow.

To avoid ambiguity in login identifiers, usernames and email addresses never collide within the same account table: a username cannot equal another user's email address, and an email address cannot equal another user's username (login looks up the username first, then the email address).

Released under the MIT License