Backend
Authentication
Authentication
The backend integrates with Casdoor as the identity provider (IDP). Authentication uses the OIDC authorization code flow with JWT access tokens.
Login flow
Auth middleware
The auth middleware (src/modules/auth/auth.middleware.ts) runs on every
protected route:
- Extracts the JWT from the
Authorization: Bearerheader - Verifies the JWT signature against Casdoor's JWKS
- Loads the user profile and role mappings from the database
- Expands the user's roles into a set of permission patterns
- Attaches
req.user(typeAuthUser) withpermissionsandisAdmin
RBAC middleware
The RBAC middleware (src/modules/auth/rbac.middleware.ts) enforces
permission checks:
- If
req.user.isAdmin === true, bypass all checks - Otherwise, match the required permission against
req.user.permissionsusing wildcard pattern matching - Support both "any" (OR) and "all" (AND) modes
Passkeys (WebAuthn)
The backend supports WebAuthn passkey enrollment and authentication:
POST /auth/webauthn/register/begin— start passkey registrationPOST /auth/webauthn/register/finish— complete registrationPOST /auth/webauthn/auth/begin— start passkey authenticationPOST /auth/webauthn/auth/finish— complete authentication
Passkeys are stored in the user_passkeys table and linked to the user
profile.
User invitations
Administrators can invite users to an organization:
POST /auth/invitations— create an invitation (admin only)GET /auth/invitations— list pending invitationsPOST /auth/invitations/:id/accept— accept an invitation
Invitations are stored in the user_invitations table with an expiry
date and a one-time token.
Organizations
The backend supports multi-tenant organizations:
POST /auth/organizations— create an organizationGET /auth/organizations— list organizationsPATCH /auth/organizations/:id— update an organizationDELETE /auth/organizations/:id— delete an organization
Users can belong to multiple organizations. Role mappings are scoped per organization.
Last modified on