Download src/core/auth/models.py from anaselamr/yaz: direct link, hf CLI and curl.
- Browser
- Download file 981 Bytes
-
https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/auth/models.py
- Command line
-
hf download hf://spaces/anaselamr/yaz/src/core/auth/models.py
-
curl -L -o models.py https://huggingface.co/spaces/anaselamr/yaz/resolve/main/src/core/auth/models.py
981 Bytes
| """ | |
| Authentication Models | |
| User token claims and authentication data structures | |
| """ | |
| from dataclasses import dataclass, field | |
| from typing import List, Optional | |
| from datetime import datetime | |
| class TokenClaims: | |
| """JWT token claims""" | |
| user_id: str | |
| username: str | |
| tenant_id: str | |
| roles: List[str] = field(default_factory=list) | |
| permissions: List[str] = field(default_factory=list) | |
| issued_at: Optional[datetime] = None | |
| expires_at: Optional[datetime] = None | |
| def has_permission(self, permission: str) -> bool: | |
| """Check if user has specific permission""" | |
| return "*" in self.permissions or permission in self.permissions | |
| def has_role(self, role: str) -> bool: | |
| """Check if user has specific role""" | |
| return role in self.roles | |
| def has_any_role(self, roles: List[str]) -> bool: | |
| """Check if user has any of the specified roles""" | |
| return any(role in self.roles for role in roles) | |