Download src/apps/auth/api/dependencies.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/apps/auth/api/dependencies.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/apps/auth/api/dependencies.py
-
curl -L -o dependencies.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/apps/auth/api/dependencies.py
1.4 kB
| """ | |
| Authentication Dependencies | |
| Common dependencies for FastAPI endpoints requiring authentication. | |
| All functions delegate to the canonical core.dependencies module. | |
| """ | |
| from typing import Optional | |
| from fastapi import Depends, HTTPException, status | |
| from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials | |
| from core.dependencies import get_current_user, CurrentUser | |
| # AuthUser alias for backward compatibility — CurrentUser has all required attrs: | |
| # .id, .user_id, .email, .username, .full_name, .role, .is_admin, .is_active, | |
| # .is_verified, .tenant_id, .permissions, .last_login | |
| AuthUser = CurrentUser | |
| security = HTTPBearer() | |
| async def get_current_active_user( | |
| current_user: CurrentUser = Depends(get_current_user), | |
| ) -> CurrentUser: | |
| """Dependency to ensure the current user is active (always True post-auth).""" | |
| if not current_user.is_active: | |
| raise HTTPException( | |
| status_code=status.HTTP_403_FORBIDDEN, | |
| detail="Inactive user", | |
| ) | |
| return current_user | |
| async def get_current_admin_user( | |
| current_user: CurrentUser = Depends(get_current_user), | |
| ) -> CurrentUser: | |
| """Dependency to ensure the current user is an admin.""" | |
| if not current_user.is_admin: | |
| raise HTTPException( | |
| status_code=status.HTTP_403_FORBIDDEN, | |
| detail="Admin access required", | |
| ) | |
| return current_user | |