Buckets:

download
raw
1.56 kB
from datetime import datetime, timedelta, timezone
from typing import Optional
import uuid
import jwt
from fastapi_otp_auth.config import settings
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
to_encode = data.copy()
if expires_delta:
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.now(timezone.utc) + timedelta(
minutes=settings.access_token_expire_minutes
)
to_encode.update({"exp": expire, "type": "access", "jti": str(uuid.uuid4())})
encoded_jwt = jwt.encode(
to_encode, settings.jwt_secret, algorithm=settings.jwt_algorithm
)
return encoded_jwt
def create_refresh_token(data: dict, expires_delta: Optional[timedelta] = None) -> str:
to_encode = data.copy()
if expires_delta:
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.now(timezone.utc) + timedelta(
days=settings.refresh_token_expire_days
)
to_encode.update({"exp": expire, "type": "refresh", "jti": str(uuid.uuid4())})
encoded_jwt = jwt.encode(
to_encode, settings.jwt_secret, algorithm=settings.jwt_algorithm
)
return encoded_jwt
def verify_token(token: str, token_type: str) -> dict:
try:
payload = jwt.decode(
token, settings.jwt_secret, algorithms=[settings.jwt_algorithm]
)
if payload.get("type") != token_type:
return None
return payload
except jwt.PyJWTError:
return None

Xet Storage Details

Size:
1.56 kB
·
Xet hash:
e64739a961aa8fbcc30bd983103f377e4372baa9c9d504eab990561b73b20244

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.