25 lines
638 B
Python
25 lines
638 B
Python
import base64
|
|
import json
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
def decode_jwt_payload(token: str) -> dict:
|
|
parts = token.split(".")
|
|
if len(parts) != 3:
|
|
raise ValueError("Invalid JWT format")
|
|
|
|
payload_b64 = parts[1]
|
|
padding = "=" * (-len(payload_b64) % 4)
|
|
raw = base64.urlsafe_b64decode(payload_b64 + padding)
|
|
return json.loads(raw.decode("utf-8"))
|
|
|
|
|
|
def unix_to_iso_utc(value: int | None) -> str | None:
|
|
if value is None:
|
|
return None
|
|
return datetime.fromtimestamp(value, tz=timezone.utc).isoformat()
|
|
|
|
|
|
def now_utc_ts() -> int:
|
|
return int(datetime.now(tz=timezone.utc).timestamp())
|