@@ -165,6 +165,7 @@ def _additional_user_info_from_token_data(token_data: dict[str, _typing.Any]):
165
165
profile = profile ,
166
166
username = username ,
167
167
is_new_user = is_new_user ,
168
+ recaptcha_score = token_data .get ("recaptcha_score" ),
168
169
)
169
170
170
171
@@ -302,9 +303,35 @@ def _validate_auth_response(
302
303
auth_response_dict ["customClaims" ] = auth_response ["custom_claims" ]
303
304
if "session_claims" in auth_response_keys :
304
305
auth_response_dict ["sessionClaims" ] = auth_response ["session_claims" ]
306
+ if "recaptcha_action_override" in auth_response_keys :
307
+ auth_response_dict ["recaptchaActionOverride" ] = auth_response [
308
+ "recaptcha_action_override" ]
305
309
return auth_response_dict
306
310
307
311
312
+ def _generate_response_payload (
313
+ auth_response_dict : dict [str , _typing .Any ] | None
314
+ ) -> dict [str , _typing .Any ]:
315
+ if not auth_response_dict :
316
+ return {}
317
+
318
+ formatted_auth_response = auth_response_dict .copy ()
319
+ recaptcha_action_override = formatted_auth_response .pop (
320
+ "recaptchaActionOverride" , None )
321
+ result = {}
322
+ update_mask = "," .join (formatted_auth_response .keys ())
323
+
324
+ if len (update_mask ) != 0 :
325
+ result ["userRecord" ] = {
326
+ ** formatted_auth_response , "updateMask" : update_mask
327
+ }
328
+
329
+ if recaptcha_action_override is not None :
330
+ result ["recaptchaActionOverride" ] = recaptcha_action_override
331
+
332
+ return result
333
+
334
+
308
335
def before_operation_handler (
309
336
func : _typing .Callable ,
310
337
event_type : str ,
@@ -329,13 +356,7 @@ def before_operation_handler(
329
356
if not auth_response :
330
357
return _jsonify ({})
331
358
auth_response_dict = _validate_auth_response (event_type , auth_response )
332
- update_mask = "," .join (auth_response_dict .keys ())
333
- result = {
334
- "userRecord" : {
335
- ** auth_response_dict ,
336
- "updateMask" : update_mask ,
337
- }
338
- }
359
+ result = _generate_response_payload (auth_response_dict )
339
360
return _jsonify (result )
340
361
# Disable broad exceptions lint since we want to handle all exceptions.
341
362
# pylint: disable=broad-except
0 commit comments