mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 03:04:27 +08:00
Allow lifetime_seconds to be None to get session cookies
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
import jwt
|
||||
|
||||
@ -6,9 +7,13 @@ JWT_ALGORITHM = "HS256"
|
||||
|
||||
|
||||
def generate_jwt(
|
||||
data: dict, lifetime_seconds: int, secret: str, algorithm: str = JWT_ALGORITHM
|
||||
data: dict,
|
||||
secret: str,
|
||||
lifetime_seconds: Optional[int] = None,
|
||||
algorithm: str = JWT_ALGORITHM,
|
||||
) -> str:
|
||||
payload = data.copy()
|
||||
expire = datetime.utcnow() + timedelta(seconds=lifetime_seconds)
|
||||
payload["exp"] = expire
|
||||
if lifetime_seconds:
|
||||
expire = datetime.utcnow() + timedelta(seconds=lifetime_seconds)
|
||||
payload["exp"] = expire
|
||||
return jwt.encode(payload, secret, algorithm=algorithm)
|
||||
|
Reference in New Issue
Block a user