Skip to content
Merged
Prev Previous commit
Next Next commit
fix: KeyError when last_sign_in_time does not exist in token_data
  • Loading branch information
exaby73 committed Oct 9, 2023
commit b56f46ca2020cb4684a5c3419fa2d4c805d9e7f8
20 changes: 11 additions & 9 deletions src/firebase_functions/private/_identity_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ def _auth_user_info_from_token_data(token_data: dict[str, _typing.Any]):
def _auth_user_metadata_from_token_data(token_data: dict[str, _typing.Any]):
from firebase_functions.identity_fn import AuthUserMetadata
creation_time = int(token_data["creation_time"]) / 1000.0
last_sign_in_time = int(token_data["last_sign_in_time"]) / 1000.0
last_sign_in_time = None
if "last_sign_in_time" in token_data:
last_sign_in_time = int(token_data["last_sign_in_time"]) / 1000.0
return AuthUserMetadata(
creation_time=_dt.datetime.utcfromtimestamp(creation_time),
last_sign_in_time=_dt.datetime.utcfromtimestamp(last_sign_in_time),
last_sign_in_time=_dt.datetime.utcfromtimestamp(last_sign_in_time) if last_sign_in_time else None,
)


Expand All @@ -89,7 +91,7 @@ def _auth_multi_factor_info_from_token_data(token_data: dict[str, _typing.Any]):


def _auth_multi_factor_settings_from_token_data(token_data: dict[str,
_typing.Any]):
_typing.Any]):
if not token_data:
return None

Expand Down Expand Up @@ -214,14 +216,14 @@ def _auth_blocking_event_from_token_data(token_data: dict[str, _typing.Any]):


def _validate_auth_response(
event_type: str,
auth_response,
event_type: str,
auth_response,
) -> dict[str, _typing.Any]:
if auth_response is None:
auth_response = {}

custom_claims: dict[str,
_typing.Any] | None = auth_response.get("custom_claims")
_typing.Any] | None = auth_response.get("custom_claims")
session_claims: dict[str, _typing.Any] | None = auth_response.get(
"session_claims")

Expand Down Expand Up @@ -303,9 +305,9 @@ def _validate_auth_response(


def before_operation_handler(
func: _typing.Callable,
event_type: str,
request: _Request,
func: _typing.Callable,
event_type: str,
request: _Request,
) -> _Response:
from firebase_functions.identity_fn import BeforeCreateResponse, BeforeSignInResponse
try:
Expand Down