整合 dsAiTeachingModel 接口
This commit is contained in:
29
dsLightRag/Routes/TeachingModel/auth/dependencies.py
Normal file
29
dsLightRag/Routes/TeachingModel/auth/dependencies.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# dependencies.py
|
||||
|
||||
from fastapi import Request, HTTPException, status, Header
|
||||
from Util.JwtUtil import *
|
||||
|
||||
async def get_current_user(token: str = Header(None, description="Authorization token")):
|
||||
if token is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="未提供令牌,请登录后使用!",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
token = token.split(" ")[1] if token.startswith("Bearer ") else token
|
||||
payload = verify_token(token)
|
||||
if payload is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="无法验证凭据,请登录后使用!",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
user_id = payload.get("user_id")
|
||||
identity_id = payload.get("identity_id")
|
||||
if user_id is None or identity_id is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="无法验证用户,请重新登录后使用!",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
return user_id
|
Reference in New Issue
Block a user