执行 Ruff 安全自动修复
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
import os
|
||||
import secrets
|
||||
import warnings
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Optional
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import bcrypt
|
||||
from jose import jwt, JWTError
|
||||
from jose import JWTError, jwt
|
||||
|
||||
# JWT 密钥:生产环境必须通过环境变量 JWT_SECRET_KEY 设置
|
||||
SECRET_KEY = os.getenv("JWT_SECRET_KEY")
|
||||
@@ -41,12 +41,12 @@ def create_access_token(
|
||||
data: dict, expires_hours: int = ACCESS_TOKEN_EXPIRE_HOURS
|
||||
) -> str:
|
||||
to_encode = data.copy()
|
||||
expire = datetime.now(timezone.utc) + timedelta(hours=expires_hours)
|
||||
expire = datetime.now(UTC) + timedelta(hours=expires_hours)
|
||||
to_encode.update({"exp": expire})
|
||||
return jwt.encode(to_encode, SECRET_KEY_TYPED, algorithm=ALGORITHM)
|
||||
|
||||
|
||||
def decode_access_token(token: str) -> Optional[dict]:
|
||||
def decode_access_token(token: str) -> dict | None:
|
||||
try:
|
||||
return jwt.decode(token, SECRET_KEY_TYPED, algorithms=[ALGORITHM])
|
||||
except JWTError:
|
||||
|
||||
Reference in New Issue
Block a user