yangdx
commited on
Commit
·
7b96a33
1
Parent(s):
d2a7d19
Added special endpoint API key checks
Browse files- lightrag/api/utils_api.py +24 -4
lightrag/api/utils_api.py
CHANGED
@@ -113,6 +113,20 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
|
|
113 |
):
|
114 |
return # API key validation successful
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
# 4. Validate token
|
117 |
if token:
|
118 |
try:
|
@@ -143,10 +157,16 @@ def get_combined_auth_dependency(api_key: Optional[str] = None):
|
|
143 |
|
144 |
# 5. No token and API key validation failed, return 403 error
|
145 |
if api_key_configured:
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
else:
|
151 |
raise HTTPException(
|
152 |
status_code=HTTP_403_FORBIDDEN, detail="Login authentication required."
|
|
|
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:
|
120 |
+
raise HTTPException(
|
121 |
+
status_code=HTTP_403_FORBIDDEN,
|
122 |
+
detail="Invalid API Key",
|
123 |
+
)
|
124 |
+
else:
|
125 |
+
raise HTTPException(
|
126 |
+
status_code=HTTP_403_FORBIDDEN,
|
127 |
+
detail="API Key required",
|
128 |
+
)
|
129 |
+
|
130 |
# 4. Validate token
|
131 |
if token:
|
132 |
try:
|
|
|
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(
|
162 |
+
status_code=HTTP_403_FORBIDDEN,
|
163 |
+
detail="API Key required or login authentication required.",
|
164 |
+
)
|
165 |
+
else:
|
166 |
+
raise HTTPException(
|
167 |
+
status_code=HTTP_403_FORBIDDEN,
|
168 |
+
detail="Invalid API Key or login authentication required.",
|
169 |
+
)
|
170 |
else:
|
171 |
raise HTTPException(
|
172 |
status_code=HTTP_403_FORBIDDEN, detail="Login authentication required."
|