yangdx commited on
Commit
4fb13b0
·
1 Parent(s): 9f458f4

Acept all if no API protection needed

Browse files
Files changed (1) hide show
  1. lightrag/api/utils_api.py +8 -4
lightrag/api/utils_api.py CHANGED
@@ -105,7 +105,7 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
105
  if is_special_endpoint and not api_key_configured:
106
  return # Special endpoint and no API key configured, allow access
107
 
108
- # 3. Validate API key
109
  if (
110
  api_key_configured
111
  and api_key_header_value
@@ -113,7 +113,7 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
113
  ):
114
  return # API key validation successful
115
 
116
- # Specail endpoint not accept token
117
  if api_key_configured and is_special_endpoint:
118
  # Special endpoint but API key validation failed, return 403 error
119
  if api_key_header_value:
@@ -127,7 +127,7 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
127
  detail="API Key required",
128
  )
129
 
130
- # 4. Validate token
131
  if token:
132
  try:
133
  token_info = auth_handler.validate_token(token)
@@ -154,8 +154,12 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
154
  status_code=status.HTTP_401_UNAUTHORIZED,
155
  detail="Invalid token. Please login again.",
156
  )
 
 
 
 
157
 
158
- # 5. No token and API key validation failed, return 403 error
159
  if api_key_configured:
160
  if api_key_header_value is None:
161
  raise HTTPException(
 
105
  if is_special_endpoint and not api_key_configured:
106
  return # Special endpoint and no API key configured, allow access
107
 
108
+ # 3. Validate API key if provided
109
  if (
110
  api_key_configured
111
  and api_key_header_value
 
113
  ):
114
  return # API key validation successful
115
 
116
+ # 4. /health and Ollama API only accept API key validation
117
  if api_key_configured and is_special_endpoint:
118
  # Special endpoint but API key validation failed, return 403 error
119
  if api_key_header_value:
 
127
  detail="API Key required",
128
  )
129
 
130
+ # 5. Validate token if provided
131
  if token:
132
  try:
133
  token_info = auth_handler.validate_token(token)
 
154
  status_code=status.HTTP_401_UNAUTHORIZED,
155
  detail="Invalid token. Please login again.",
156
  )
157
+
158
+ # 5. Acept all if no API protection needed
159
+ if not auth_configured and not api_key_configured:
160
+ return
161
 
162
+ # 5. Otherwise: refuse access and return 403 error
163
  if api_key_configured:
164
  if api_key_header_value is None:
165
  raise HTTPException(