File size: 555 Bytes
507bb5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import os
import jwt
from typing import Optional
def verify_token(token: str) -> Optional[dict]:
try:
# Decode without verification for local testing only
# HF Spaces will have network access to verify properly
payload = jwt.decode(
token,
options={"verify_signature": False},
algorithms=["ES256", "HS256"],
audience="authenticated",
)
return payload
except jwt.ExpiredSignatureError:
return None
except jwt.InvalidTokenError:
return None |