9
9
HTTPBasic ,
10
10
OAuth2PasswordBearer ,
11
11
)
12
+ from starlette .datastructures import FormData
12
13
13
14
from keep .api .core .config import config
14
15
from keep .api .core .db import get_api_key , update_key_last_used
16
+ from keep .api .core .dependencies import extract_generic_body
15
17
from keep .identitymanager .authenticatedentity import AuthenticatedEntity
16
18
from keep .identitymanager .rbac import Admin as AdminRole
17
19
from keep .identitymanager .rbac import get_role_by_role_name
@@ -97,6 +99,7 @@ def __call__(
97
99
api_key : Optional [str ] = Security (auth_header ),
98
100
authorization : Optional [HTTPAuthorizationCredentials ] = Security (http_basic ),
99
101
token : Optional [str ] = Depends (oauth2_scheme ),
102
+ body : dict | bytes | FormData = Depends (extract_generic_body ),
100
103
) -> AuthenticatedEntity :
101
104
"""
102
105
Main entry point for authentication and authorization.
@@ -123,7 +126,7 @@ def __call__(
123
126
detail = "Read only instance, but non-read scopes requested" ,
124
127
)
125
128
126
- authenticated_entity = self .authenticate (request , api_key , authorization , token )
129
+ authenticated_entity = self .authenticate (request , api_key , authorization , token , body )
127
130
self .logger .debug (
128
131
f"Authentication successful for entity: { authenticated_entity } "
129
132
)
@@ -140,6 +143,7 @@ def authenticate(
140
143
api_key : Optional [str ],
141
144
authorization : Optional [HTTPAuthorizationCredentials ],
142
145
token : Optional [str ],
146
+ body : Optional [dict | bytes | FormData ] = None ,
143
147
) -> AuthenticatedEntity :
144
148
"""
145
149
Authenticate the request using either token, API key, or HTTP basic auth.
@@ -149,6 +153,7 @@ def authenticate(
149
153
api_key (Optional[str]): The API key from the header.
150
154
authorization (Optional[HTTPAuthorizationCredentials]): The HTTP basic auth credentials.
151
155
token (Optional[str]): The OAuth2 token.
156
+ body (Optional[dict | bytes | FormData]): incoming request body got logs
152
157
153
158
Returns:
154
159
AuthenticatedEntity: The authenticated entity.
@@ -189,6 +194,7 @@ def authenticate(
189
194
"No valid authentication method found" ,
190
195
extra = {
191
196
"headers" : request .headers ,
197
+ "body" : request .body ,
192
198
}
193
199
)
194
200
raise HTTPException (
0 commit comments