Skip to content

fix: crash with InvalidAuthBlockingTokenError #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 changes: 1 addition & 1 deletion src/firebase_functions/identity_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AuthUserMetadata:
creation_time: _dt.datetime
"""The date the user was created."""

last_sign_in_time: _dt.datetime
last_sign_in_time: _typing.Optional[_dt.datetime]
"""The date the user last signed in."""


Expand Down
15 changes: 9 additions & 6 deletions src/firebase_functions/private/_identity_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ 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
return AuthUserMetadata(
creation_time=_dt.datetime.utcfromtimestamp(
token_data["creation_time"] / 1000.0),
last_sign_in_time=_dt.datetime.utcfromtimestamp(
token_data["last_sign_in_time"] / 1000.0),
)
creation_time = _dt.datetime.utcfromtimestamp(
int(token_data["creation_time"]) / 1000.0)
last_sign_in_time = None
if "last_sign_in_time" in token_data:
last_sign_in_time = _dt.datetime.utcfromtimestamp(
int(token_data["last_sign_in_time"]) / 1000.0)

return AuthUserMetadata(creation_time=creation_time,
last_sign_in_time=last_sign_in_time)


def _auth_multi_factor_info_from_token_data(token_data: dict[str, _typing.Any]):
Expand Down
4 changes: 2 additions & 2 deletions src/firebase_functions/private/token_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ def verify(self, token, request):
'Firebase {0} has incorrect algorithm. Expected "RS256" but got '
'"{1}". {2}'.format(self.short_name, header.get('alg'),
verify_id_token_msg))
elif self.expected_audience and self.expected_audience not in audience:
elif not emulated and self.expected_audience and self.expected_audience not in audience:
error_message = (
'Firebase {0} has incorrect "aud" (audience) claim. Expected "{1}" but '
'got "{2}". {3} {4}'.format(self.short_name,
self.expected_audience, audience,
project_id_match_msg,
verify_id_token_msg))
elif not self.expected_audience and audience != self.project_id:
elif not emulated and not self.expected_audience and audience != self.project_id:
error_message = (
'Firebase {0} has incorrect "aud" (audience) claim. Expected "{1}" but '
'got "{2}". {3} {4}'.format(self.short_name, self.project_id,
Expand Down