Authentication manager
| 10 | optional_security = HTTPBearer(auto_error=False) |
| 11 | |
| 12 | class AuthManager: |
| 13 | """Authentication manager""" |
| 14 | |
| 15 | @staticmethod |
| 16 | def verify_api_key(api_key: str) -> bool: |
| 17 | """Verify API key""" |
| 18 | return api_key == config.api_key |
| 19 | |
| 20 | @staticmethod |
| 21 | def verify_admin(username: str, password: str) -> bool: |
| 22 | """Verify admin credentials""" |
| 23 | # Compare with current config (which may be from database or config file) |
| 24 | return username == config.admin_username and password == config.admin_password |
| 25 | |
| 26 | @staticmethod |
| 27 | def hash_password(password: str) -> str: |
| 28 | """Hash password""" |
| 29 | return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode() |
| 30 | |
| 31 | @staticmethod |
| 32 | def verify_password(password: str, hashed: str) -> bool: |
| 33 | """Verify password""" |
| 34 | return bcrypt.checkpw(password.encode(), hashed.encode()) |
| 35 | |
| 36 | async def verify_api_key_header(credentials: HTTPAuthorizationCredentials = Security(security)) -> str: |
| 37 | """Verify API key from Authorization header""" |
nothing calls this directly
no outgoing calls
no test coverage detected