mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
15 lines
374 B
Python
15 lines
374 B
Python
from datetime import datetime, timedelta
|
|
|
|
import jwt
|
|
|
|
JWT_ALGORITHM = "HS256"
|
|
|
|
|
|
def generate_jwt(
|
|
data: dict, lifetime_seconds: int, secret: str, algorithm: str = JWT_ALGORITHM
|
|
) -> str:
|
|
payload = data.copy()
|
|
expire = datetime.utcnow() + timedelta(seconds=lifetime_seconds)
|
|
payload["exp"] = expire
|
|
return jwt.encode(payload, secret, algorithm=algorithm)
|