big update new dashboard and import export
This commit is contained in:
@@ -41,6 +41,7 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
|
||||
to_encode = data.copy()
|
||||
expire = datetime.now(timezone.utc) + (expires_delta or timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
||||
to_encode["exp"] = expire
|
||||
to_encode["jti"] = str(uuid.uuid4()) # уникальный ID токена для блэклиста
|
||||
return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
||||
|
||||
|
||||
@@ -51,6 +52,7 @@ def get_session():
|
||||
|
||||
def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
"""FastAPI dependency: валидирует Bearer-токен и возвращает объект User."""
|
||||
from redis_db import is_token_blacklisted
|
||||
credentials_exc = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Could not validate credentials",
|
||||
@@ -59,8 +61,15 @@ def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
try:
|
||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||
user_id: str = payload.get("sub")
|
||||
jti: str = payload.get("jti")
|
||||
if user_id is None:
|
||||
raise credentials_exc
|
||||
if jti and is_token_blacklisted(jti):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Token has been revoked",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
except JWTError:
|
||||
raise credentials_exc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user