mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-05-09 05:35:30 +02:00
[PR #117] [MERGED] Added optional authentication and user management #931
Labels
No labels
A1
automated
automated
bug
bug
Closed due to inactivity
contrib
dependencies
dependencies
duplicate
enhancement
feedback
hold
invalid
Notes
P1S
pull-request
security
security
ThumbsUp
user-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/bambuddy#931
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/maziggy/bambuddy/pull/117
Author: @JesseFPV
Created: 1/21/2026
Status: ✅ Merged
Merged: 1/21/2026
Merged by: @maziggy
Base:
main← Head:main📝 Commits (5)
f8857baAdded optional authentication and user management3e1843fUpdated checksd731cd2Fixed lint errorsdeeaabfFixed frontend lint test error6e5cc55Fixed auth check and conftest📊 Changes
30 files changed (+10808 additions, -8775 deletions)
View changed files
➕
backend/app/api/routes/auth.py(+213 -0)📝
backend/app/api/routes/printers.py(+4 -0)➕
backend/app/api/routes/users.py(+205 -0)📝
backend/app/core/auth.py(+306 -61)📝
backend/app/core/database.py(+20 -0)📝
backend/app/main.py(+4 -0)📝
backend/app/models/__init__.py(+2 -0)➕
backend/app/models/user.py(+20 -0)➕
backend/app/schemas/auth.py(+47 -0)📝
backend/tests/conftest.py(+1 -0)📝
frontend/package-lock.json(+39 -14)📝
frontend/package.json(+1 -0)📝
frontend/src/App.tsx(+89 -23)📝
frontend/src/__tests__/components/Layout.test.tsx(+3 -0)📝
frontend/src/__tests__/pages/SettingsPage.test.tsx(+3 -0)📝
frontend/src/__tests__/utils.tsx(+4 -1)📝
frontend/src/api/client.ts(+121 -4)📝
frontend/src/components/Layout.tsx(+33 -1)➕
frontend/src/contexts/AuthContext.tsx(+116 -0)➕
frontend/src/pages/LoginPage.tsx(+103 -0)...and 10 more files
📄 Description
Description
This PR adds a comprehensive authentication and authorization system to Bambuddy, allowing administrators to secure their instance with user authentication and role-based access control. The system is fully optional and maintains backward compatibility - existing installations without authentication will continue to work as before.
Related Issue
Fixes #
Type of Change
Changes Made
Backend Changes
User Model & Database Migration
Usermodel with username, password hash, role, and active statususerstable with proper indexesadminanduserAuthentication Core (
backend/app/core/auth.py)pbkdf2_sha256(secure alternative to bcrypt without 72-byte limit)get_current_user- Requires valid JWT tokenget_current_active_user- Requires active user accountrequire_auth_if_enabled- Optional auth when enabledrequire_role(role)- Role-based access controlRequireAdmin()- Admin-only dependencyRequireAdminIfAuthEnabled()- Admin-only when auth is enabledget_api_key,check_permission,check_printer_access)Authentication Routes (
backend/app/api/routes/auth.py)POST /auth/setup- First-time setup to enable/disable authentication and create admin userGET /auth/status- Public endpoint to check authentication statusPOST /auth/login- User login endpoint (returns JWT token)GET /auth/me- Get current user informationPOST /auth/logout- Logout endpoint (client-side token removal)POST /auth/disable- Admin-only endpoint to disable authenticationUser Management Routes (
backend/app/api/routes/users.py)GET /users- List all users (admin only)POST /users- Create new user (admin only)GET /users/{id}- Get user details (admin only)PUT /users/{id}- Update user (admin only)DELETE /users/{id}- Delete user (admin only)Route Protection
RequireAdminIfAuthEnabledRequireAdminFrontend Changes
Authentication Context (
frontend/src/contexts/AuthContext.tsx)New Pages
frontend/src/pages/SetupPage.tsx)frontend/src/pages/LoginPage.tsx)frontend/src/pages/UsersPage.tsx)Settings Page Updates
Layout & Navigation (
frontend/src/components/Layout.tsx)Route Protection (
frontend/src/App.tsx)ProtectedRoute- Requires authentication when enabledAdminRoute- Requires admin role (used for Settings page)SetupRoute- Only accessible when authentication not enabledAdminRouteAPI Client (
frontend/src/api/client.ts)getAuthToken,setAuthToken)getAuthStatus()- Check authentication statussetupAuth()- Configure authenticationlogin()- User loginlogout()- User logoutgetCurrentUser()- Get current user infogetUsers()- List users (admin)createUser()- Create user (admin)updateUser()- Update user (admin)deleteUser()- Delete user (admin)disableAuth()- Disable authentication (admin)Security Features
Password Security
pbkdf2_sha256(no length limitations)Token Security
Role-Based Access Control
Backward Compatibility
Screenshots
Testing
Test Scenarios
First-time Setup
Authentication Flow
Role-Based Access
User Management
Disable Authentication
Backward Compatibility
Checklist
Additional Notes
Technical Decisions
Password Hashing: Chose
pbkdf2_sha256overbcryptto avoid the 72-byte password length limitation. This ensures users can use long, complex passwords without truncation.JWT Tokens: Using JWT for stateless authentication. Tokens expire after 7 days and are automatically validated on each API request.
Route Protection: Implemented flexible dependency system that allows routes to be protected only when authentication is enabled, maintaining backward compatibility.
UI/UX: Applied Bambuddy branding to setup and login pages, ensuring consistent user experience. Used existing design system components (Card, Button, ConfirmModal) for user management interface.
Future Enhancements
Migration Notes
userstable on first run🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.