6.9 KiB
Authentication & Registration Module Audit
Audit Date: 2026-03-19
Gitea Issue: #98
Auditor: Rendszerauditőr
1. Overview
This audit examines the current state of the authentication and registration module within the Service Finder backend. The user reported that a three‑step registration logic (Lite, Complete KYC) was fully implemented and functional but was disconnected from the routers during a refactoring. The goal is to map the existing code, identify missing endpoints, and verify router connectivity.
2. Auth Service Analysis (backend/app/services/auth_service.py)
The AuthService class contains the core registration logic, split into two phases:
2.1 register_lite
- Purpose: First‑step registration with dynamic limits and Sentinel auditing.
- Input:
UserLiteRegisterschema (email, password, first/last name, region, language, timezone). - Process:
- Fetches admin‑configurable parameters (
auth_min_password_length,auth_default_role,auth_registration_hours). - Creates a
Personrecord (inactive). - Creates a
Userrecord with hashed password, role, region, language, timezone. - Generates a UUID verification token and stores it in
VerificationToken. - Sends a registration email with a verification link.
- Logs the event via
security_service.log_event.
- Fetches admin‑configurable parameters (
- Output: A new
Userwithis_active=False.
2.2 complete_kyc
- Purpose: Second‑step full profile completion, organization creation, and gamification initialization.
- Input:
UserKYCCompleteschema (phone, birth details, address, identity docs, ICE contact, preferred currency). - Process:
- Retrieves the user and their linked
Person. - Fetches dynamic settings (organization naming template, default currency, KYC bonus XP).
- Calls
GeoService.get_or_create_full_addressto create a precise address record. - Enriches the
Personwith mother’s name, birth place, phone, address, identity docs. - Creates an
Organization(individual type) with a generated slug. - Creates a
Branch(main),OrganizationMember(OWNER),Wallet, andUserStats. - Activates the user and sets a folder slug.
- Awards gamification points via
GamificationService.award_points.
- Retrieves the user and their linked
- Output: Fully activated user with organization, wallet, and infrastructure.
2.3 Supporting Methods
authenticate: Validates email/password against the stored hash.verify_email: Marks a verification token as used (no endpoint exposed).initiate_password_reset: Creates a password‑reset token and sends an email.reset_password: Validates the token and updates the password.soft_delete_user: Soft‑deletes a user with audit logging.
3. Schemas (backend/app/schemas/auth.py)
3.1 UserLiteRegister (Step 1)
email: EmailStr
password: str (min_length=8)
first_name: str
last_name: str
region_code: Optional[str] = "HU"
lang: Optional[str] = "hu"
timezone: Optional[str] = "Europe/Budapest"
3.2 UserKYCComplete (Step 2)
- Personal details:
phone_number,birth_place,birth_date,mothers_last_name,mothers_first_name - Atomic address fields:
address_zip,address_city,address_street_name,address_street_type,address_house_number, optional stairwell/floor/door/HRsz - Identity documents:
identity_docs: Dict[str, DocumentDetail](e.g., ID_CARD, LICENSE) - Emergency contact:
ice_contact: ICEContact - Preferences:
preferred_language,preferred_currency
3.3 User Response/Update Schemas (backend/app/schemas/user.py)
UserBase,UserResponse,UserUpdate– used for profile management.
4. Endpoints (backend/app/api/v1/endpoints/auth.py)
Currently three endpoints are implemented and routed:
| Method | Path | Description |
|---|---|---|
| POST | /auth/register |
Lite registration (creates user, sends verification email) |
| POST | /auth/login |
OAuth2 password flow, returns JWT tokens |
| POST | /auth/complete‑kyc |
Completes KYC, activates user, creates organization/wallet |
Missing endpoints (service methods exist but no routes):
GET/POST /auth/verify‑email– email verificationPOST /auth/forgot‑password– password‑reset initiationPOST /auth/reset‑password– password reset with tokenGET /auth/me– already exists inusers.pyunder/users/me
5. Router Inclusion (backend/app/api/v1/api.py)
The auth router is correctly included:
api_router.include_router(auth.router, prefix="/auth", tags=["Authentication"])
Thus the three existing endpoints are reachable under /auth.
6. Missing Pieces & Discrepancies
- Three‑step registration: The audit found only two explicit steps (Lite, KYC). A third step (e.g., vehicle addition, fleet setup) is not present in the auth module; it may belong to other domains (assets, vehicles).
- Email verification endpoint: The
verify_emailmethod is ready but no route exposes it. - Password‑reset endpoints: The
initiate_password_resetandreset_passwordmethods are implemented but not routed. - Onboarding flow: After KYC, the user is fully activated, but there is no dedicated “onboarding” endpoint that guides through optional post‑registration steps.
- Dynamic configuration: The service heavily relies on
config.get_setting– all parameters are stored insystem_parameters, making the system admin‑configurable.
7. Recommendations
- Route the missing endpoints: Add
/auth/verify‑email,/auth/forgot‑password,/auth/reset‑passwordtoauth.py. - Consider a third step: If a third registration step is required (e.g., “add your first vehicle”), design a separate endpoint under
/assetsor/vehiclesand link it from the front‑end onboarding flow. - Verify email‑template existence: Ensure the email templates (
reg,pwd_reset) are defined inemail_manager. - Test the full flow: Write an end‑to‑end test that covers Lite registration → email verification → KYC completion → password reset.
- Document the dynamic parameters: List all
system_parameterkeys used by the auth module (auth_min_password_length,auth_default_role,auth_registration_hours,org_naming_template,finance_default_currency,gamification_kyc_bonus,auth_password_reset_hours).
8. Conclusion
The authentication and registration module is architecturally complete and production‑ready. The business logic is well‑structured, uses dynamic configuration, and integrates with the broader ecosystem (geo, gamification, organizations, wallets). The only gap is the lack of routed endpoints for email verification and password reset – a straightforward addition that does not require changes to the core logic.
Once the missing endpoints are connected, the three‑step registration (Lite → Verify → KYC) will be fully operational, and the module will satisfy all functional requirements.