Skip to content

Commit 6fd96fe

Browse files
committed
fix: crash with InvalidAuthBlockingTokenError (wrong audience)
1 parent f463ed1 commit 6fd96fe

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/firebase_functions/private/_identity_fn.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def _auth_user_info_from_token_data(token_data: dict[str, _typing.Any]):
6464

6565
def _auth_user_metadata_from_token_data(token_data: dict[str, _typing.Any]):
6666
from firebase_functions.identity_fn import AuthUserMetadata
67+
creation_time = int(token_data["creation_time"]) / 1000.0
68+
last_sign_in_time = int(token_data["last_sign_in_time"]) / 1000.0
6769
return AuthUserMetadata(
68-
creation_time=_dt.datetime.utcfromtimestamp(
69-
token_data["creation_time"] / 1000.0),
70-
last_sign_in_time=_dt.datetime.utcfromtimestamp(
71-
token_data["last_sign_in_time"] / 1000.0),
70+
creation_time=_dt.datetime.utcfromtimestamp(creation_time),
71+
last_sign_in_time=_dt.datetime.utcfromtimestamp(last_sign_in_time),
7272
)
7373

7474

src/firebase_functions/private/token_verifier.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ def verify(self, token, request):
9595
'Firebase {0} has incorrect algorithm. Expected "RS256" but got '
9696
'"{1}". {2}'.format(self.short_name, header.get('alg'),
9797
verify_id_token_msg))
98-
elif self.expected_audience and self.expected_audience not in audience:
98+
elif not emulated and self.expected_audience and self.expected_audience not in audience:
9999
error_message = (
100100
'Firebase {0} has incorrect "aud" (audience) claim. Expected "{1}" but '
101101
'got "{2}". {3} {4}'.format(self.short_name,
102102
self.expected_audience, audience,
103103
project_id_match_msg,
104104
verify_id_token_msg))
105-
elif not self.expected_audience and audience != self.project_id:
105+
elif not emulated and not self.expected_audience and audience != self.project_id:
106106
error_message = (
107107
'Firebase {0} has incorrect "aud" (audience) claim. Expected "{1}" but '
108108
'got "{2}". {3} {4}'.format(self.short_name, self.project_id,

0 commit comments

Comments
 (0)