Authentication API
1. "User login"
- route definition
- Url: /api/v1/auth/login
- Method: POST
- Request:
LoginRequest - Response:
LoginResponse
- request definition
go
type LoginRequest struct {
Username string `json:"username"` // username
Password string `json:"password"` // password
}- response definition
go
type LoginResponse struct {
Token string `json:"token"`
User UserInfo `json:"user"`
LastGameID string `json:"lastGameId,omitempty"`
LastEnv string `json:"lastEnv,omitempty"`
MustChangePassword bool `json:"mustChangePassword,omitempty"`
MFASetupRequired bool `json:"mfaSetupRequired,omitempty"`
}
type UserInfo struct {
Username string `json:"username"`
Roles []string `json:"roles"`
Nickname string `json:"nickname"`
}2. "User logout"
- route definition
- Url: /api/v1/auth/logout
- Method: POST
- Request:
LogoutRequest - Response:
LogoutResponse
- request definition
go
type LogoutRequest struct {
}- response definition
go
type LogoutResponse struct {
}3. "Permission check"
- route definition
- Url: /api/v1/auth/check
- Method: POST
- Auth: Bearer Token
- Request:
CheckRequest - Response:
CheckResponse
- request definition
go
type CheckRequest struct {
Resource string `json:"resource"` // e.g. roles, games, functions
Action string `json:"action"` // e.g. read, write, manage
GameID string `json:"gameId,omitempty"`
Env string `json:"env,omitempty"`
}- response definition
go
type CheckResponse struct {
Allowed bool `json:"allowed"`
Reason string `json:"reason,omitempty"`
}4. "Batch permission check"
- route definition
- Url: /api/v1/auth/check/batch
- Method: POST
- Auth: Bearer Token
- Request:
BatchCheckRequest - Response:
BatchCheckResponse
- request definition
go
type BatchCheckRequest struct {
Checks []CheckRequest `json:"checks"`
}- response definition
go
type BatchCheckResponse struct {
Results []CheckResponse `json:"results"`
}Notes
- Checks are based on the logged-in user's roles and permissions in the database, not on frontend caches.
- The
gameIdandenvfields are currently kept for compatibility with the frontend request shape; permission decisions are currently made by resource and action.
External Identity Source Endpoints
The following endpoints become available when auth.providers is enabled; when disabled, providers returns all local and the OIDC endpoints return 400.
Query Enabled Login Methods
- Url: /api/v1/auth/providers
- Method: GET
- Auth: none
json
{
"local": true,
"ldap": true,
"oidc": false,
"github": false,
"wechat": false,
"genericoauth": false,
"register": true
}Start an OIDC Login
- Url: /api/v1/auth/oidc/login
- Method: GET
- Auth: none
- Behavior: 302 redirect to the identity source's authorization page; state carries an HMAC signature and a 10-minute validity
OIDC Callback
- Url: /api/v1/auth/oidc/callback?code=xxx&state=xxx
- Method: GET
- Auth: none
- Response:
LoginResponse(same as password login); whenloginSuccessUrlis configured, instead a 302 carrying?token=xxxredirects to the frontend
Self-Service Registration and Email Verification (both anonymous)
POST /api/v1/auth/register— self-service registration (theauth.providers.registerswitch defaults to off)GET /api/v1/auth/verify-email— email verification callback (the token is the credential)POST /api/v1/auth/resend-verification— resend the verification email by username+email (anti-enumeration silence at the service layer)
OAuth Logins (all anonymous, same semantics family)
| Provider | Start | Callback |
|---|---|---|
| OIDC | GET /api/v1/auth/oidc/login | GET /api/v1/auth/oidc/callback |
| GitHub | GET /api/v1/auth/github/login | GET /api/v1/auth/github/callback |
| WeChat QR | GET /api/v1/auth/wechat/login | GET /api/v1/auth/wechat/callback |
| Custom OAuth2 | GET /api/v1/auth/generic/login | GET /api/v1/auth/generic/callback |
MFA (TOTP; authentication required)
The server enforces two steps: before confirmation, login returns 401 mfa_required.
GET /api/v1/auth/mfa/status— whether MFA is enabledPOST /api/v1/auth/mfa/setup— generate a TOTP secret and otpauth URLPOST /api/v1/auth/mfa/confirm— confirm the first code, activating MFA (returns backup recovery codes)POST /api/v1/auth/mfa/disable— disable MFA (requires a code)
Backup recovery codes live in the admin_otp_recovery_codes table (migration 0032).
