Skip to content

Commit a9f7ead

Browse files
Log request body in case of No valid authentication method found
1 parent 2c821c9 commit a9f7ead

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

keep/identitymanager/authverifierbase.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
HTTPBasic,
1010
OAuth2PasswordBearer,
1111
)
12+
from starlette.datastructures import FormData
1213

1314
from keep.api.core.config import config
1415
from keep.api.core.db import get_api_key, update_key_last_used
16+
from keep.api.core.dependencies import extract_generic_body
1517
from keep.identitymanager.authenticatedentity import AuthenticatedEntity
1618
from keep.identitymanager.rbac import Admin as AdminRole
1719
from keep.identitymanager.rbac import get_role_by_role_name
@@ -97,6 +99,7 @@ def __call__(
9799
api_key: Optional[str] = Security(auth_header),
98100
authorization: Optional[HTTPAuthorizationCredentials] = Security(http_basic),
99101
token: Optional[str] = Depends(oauth2_scheme),
102+
body: dict | bytes | FormData = Depends(extract_generic_body),
100103
) -> AuthenticatedEntity:
101104
"""
102105
Main entry point for authentication and authorization.
@@ -123,7 +126,7 @@ def __call__(
123126
detail="Read only instance, but non-read scopes requested",
124127
)
125128

126-
authenticated_entity = self.authenticate(request, api_key, authorization, token)
129+
authenticated_entity = self.authenticate(request, api_key, authorization, token, body)
127130
self.logger.debug(
128131
f"Authentication successful for entity: {authenticated_entity}"
129132
)
@@ -140,6 +143,7 @@ def authenticate(
140143
api_key: Optional[str],
141144
authorization: Optional[HTTPAuthorizationCredentials],
142145
token: Optional[str],
146+
body: Optional[dict | bytes | FormData] = None,
143147
) -> AuthenticatedEntity:
144148
"""
145149
Authenticate the request using either token, API key, or HTTP basic auth.
@@ -149,6 +153,7 @@ def authenticate(
149153
api_key (Optional[str]): The API key from the header.
150154
authorization (Optional[HTTPAuthorizationCredentials]): The HTTP basic auth credentials.
151155
token (Optional[str]): The OAuth2 token.
156+
body (Optional[dict | bytes | FormData]): incoming request body got logs
152157
153158
Returns:
154159
AuthenticatedEntity: The authenticated entity.
@@ -189,6 +194,7 @@ def authenticate(
189194
"No valid authentication method found",
190195
extra={
191196
"headers": request.headers,
197+
"body": request.body,
192198
}
193199
)
194200
raise HTTPException(

0 commit comments

Comments
 (0)