@@ -137,7 +137,7 @@ def __init__(
137
137
Union [BaseResponse , Awaitable [BaseResponse ]],
138
138
],
139
139
on_invalid_claim : Callable [
140
- [BaseRequest , List [Dict [ str , Any ] ], BaseResponse ],
140
+ [BaseRequest , List [ClaimValidationError ], BaseResponse ],
141
141
Union [BaseResponse , Awaitable [BaseResponse ]],
142
142
],
143
143
):
@@ -185,7 +185,7 @@ async def on_invalid_claim(
185
185
self ,
186
186
recipe : SessionRecipe ,
187
187
request : BaseRequest ,
188
- claim_validation_errors : List [Dict [ str , Any ] ],
188
+ claim_validation_errors : List [ClaimValidationError ],
189
189
response : BaseResponse ,
190
190
):
191
191
_ = recipe
@@ -214,7 +214,7 @@ def __init__(
214
214
] = None ,
215
215
on_invalid_claim : Union [
216
216
Callable [
217
- [BaseRequest , List [Dict [ str , Any ] ], BaseResponse ],
217
+ [BaseRequest , List [ClaimValidationError ], BaseResponse ],
218
218
Union [BaseResponse , Awaitable [BaseResponse ]],
219
219
],
220
220
None ,
@@ -275,13 +275,23 @@ async def default_token_theft_detected_callback(
275
275
276
276
async def default_invalid_claim_callback (
277
277
_ : BaseRequest ,
278
- claim_validation_errors : List [Dict [ str , Any ] ],
278
+ claim_validation_errors : List [ClaimValidationError ],
279
279
response : BaseResponse ,
280
280
) -> BaseResponse :
281
281
from .recipe import SessionRecipe
282
282
283
+ payload : List [Dict [str , Any ]] = []
284
+
285
+ for p in claim_validation_errors :
286
+ res = (
287
+ p .__dict__ .copy ()
288
+ ) # Must be JSON serializable as it will be used in response
289
+ if p .reason is None :
290
+ res .pop ("reason" )
291
+ payload .append (res )
292
+
283
293
return send_non_200_response (
284
- {"message" : "invalid claim" , "claimValidationErrors" : claim_validation_errors },
294
+ {"message" : "invalid claim" , "claimValidationErrors" : payload },
285
295
SessionRecipe .get_instance ().config .invalid_claim_status_code ,
286
296
response ,
287
297
)
0 commit comments