mirror of
https://github.com/open-webui/open-webui
synced 2025-03-26 07:27:40 +00:00
fix
This commit is contained in:
parent
1e0453221d
commit
ab270c1682
@ -325,6 +325,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
|||||||
data = json.loads(body_str) if body_str else {}
|
data = json.loads(body_str) if body_str else {}
|
||||||
|
|
||||||
user = get_current_user(
|
user = get_current_user(
|
||||||
|
request,
|
||||||
get_http_authorization_cred(request.headers.get("Authorization"))
|
get_http_authorization_cred(request.headers.get("Authorization"))
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -558,6 +559,7 @@ class PipelineMiddleware(BaseHTTPMiddleware):
|
|||||||
data = json.loads(body_str) if body_str else {}
|
data = json.loads(body_str) if body_str else {}
|
||||||
|
|
||||||
user = get_current_user(
|
user = get_current_user(
|
||||||
|
request,
|
||||||
get_http_authorization_cred(request.headers.get("Authorization"))
|
get_http_authorization_cred(request.headers.get("Authorization"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ ALGORITHM = "HS256"
|
|||||||
##############
|
##############
|
||||||
|
|
||||||
bearer_security = HTTPBearer(auto_error=False)
|
bearer_security = HTTPBearer(auto_error=False)
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
|
|
||||||
|
|
||||||
@ -79,15 +78,17 @@ def get_current_user(
|
|||||||
request: Request,
|
request: Request,
|
||||||
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
|
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
|
||||||
):
|
):
|
||||||
# get token from cookie
|
token = None
|
||||||
token = request.cookies.get("token")
|
|
||||||
|
|
||||||
if auth_token is None and token is None:
|
|
||||||
raise HTTPException(status_code=403, detail="Not authenticated")
|
|
||||||
|
|
||||||
if auth_token is not None:
|
if auth_token is not None:
|
||||||
token = auth_token.credentials
|
token = auth_token.credentials
|
||||||
|
|
||||||
|
if token is None and "token" in request.cookies:
|
||||||
|
token = request.cookies.get("token")
|
||||||
|
|
||||||
|
if token is None:
|
||||||
|
raise HTTPException(status_code=403, detail="Not authenticated")
|
||||||
|
|
||||||
# auth by api key
|
# auth by api key
|
||||||
if token.startswith("sk-"):
|
if token.startswith("sk-"):
|
||||||
return get_current_user_by_api_key(token)
|
return get_current_user_by_api_key(token)
|
||||||
|
Loading…
Reference in New Issue
Block a user