28 lines
662 B
Python
28 lines
662 B
Python
from datetime import datetime
|
|
|
|
from jose import jwt # type: ignore[import-untyped]
|
|
|
|
from src.config import Settings
|
|
|
|
|
|
def mint_access_token(
|
|
*,
|
|
settings: Settings,
|
|
subject: str,
|
|
email: str,
|
|
name: str,
|
|
expires_at: datetime,
|
|
) -> str:
|
|
payload = {
|
|
"sub": subject,
|
|
"email": email,
|
|
"name": name,
|
|
"exp": expires_at,
|
|
}
|
|
return jwt.encode(payload, settings.jwt_secret, algorithm=settings.jwt_algorithm)
|
|
|
|
|
|
def decode_access_token(*, settings: Settings, token: str) -> dict[str, str | int]:
|
|
claims = jwt.decode(token, settings.jwt_secret, algorithms=[settings.jwt_algorithm])
|
|
return dict(claims)
|