Initial FastAPI admin auth scaffold
This commit is contained in:
23
app/lib/jwt/token.py
Normal file
23
app/lib/jwt/token.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class JwtToken:
|
||||
raw: str
|
||||
claims: dict[str, Any]
|
||||
|
||||
@property
|
||||
def jwt_id(self) -> str:
|
||||
return str(self.claims.get("jti", ""))
|
||||
|
||||
@property
|
||||
def admin_id(self) -> int:
|
||||
try:
|
||||
return int(self.jwt_id)
|
||||
except ValueError:
|
||||
return 0
|
||||
|
||||
@property
|
||||
def is_refresh(self) -> bool:
|
||||
return self.claims.get("sub") == "refresh" or self.claims.get("token_type") == "refresh"
|
||||
Reference in New Issue
Block a user