@@ -165,6 +165,7 @@ def _additional_user_info_from_token_data(token_data: dict[str, _typing.Any]):
165165 profile = profile ,
166166 username = username ,
167167 is_new_user = is_new_user ,
168+ recaptcha_score = token_data .get ("recaptcha_score" ),
168169 )
169170
170171
@@ -302,9 +303,35 @@ def _validate_auth_response(
302303 auth_response_dict ["customClaims" ] = auth_response ["custom_claims" ]
303304 if "session_claims" in auth_response_keys :
304305 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" ]
305309 return auth_response_dict
306310
307311
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+
308335def before_operation_handler (
309336 func : _typing .Callable ,
310337 event_type : str ,
@@ -329,13 +356,7 @@ def before_operation_handler(
329356 if not auth_response :
330357 return _jsonify ({})
331358 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 )
339360 return _jsonify (result )
340361 # Disable broad exceptions lint since we want to handle all exceptions.
341362 # pylint: disable=broad-except
0 commit comments