Skip to content

Commit c31fc24

Browse files
committed
Merge branch 'main' into feat/logger
2 parents a02b001 + d06ccb6 commit c31fc24

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/firebase_functions/identity_fn.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
"""Cloud functions to handle Eventarc events."""
1515

16-
# pylint: disable=protected-access
16+
# pylint: disable=protected-access,cyclic-import
1717
import typing as _typing
1818
import functools as _functools
1919
import datetime as _dt
@@ -59,7 +59,7 @@ class AuthUserMetadata:
5959
creation_time: _dt.datetime
6060
"""The date the user was created."""
6161

62-
last_sign_in_time: _dt.datetime
62+
last_sign_in_time: _typing.Optional[_dt.datetime]
6363
"""The date the user last signed in."""
6464

6565

@@ -345,7 +345,7 @@ def example(event: identity_fn.AuthBlockingEvent) -> identity_fn.BeforeSignInRes
345345
:param \\*\\*kwargs: Options.
346346
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BlockingOptions`
347347
:rtype: :exc:`typing.Callable`
348-
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
348+
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
349349
:exc:`firebase_functions.identity_fn.BeforeSignInResponse` \\| `None` \\]
350350
A function that takes a AuthBlockingEvent and optionally returns BeforeSignInResponse.
351351
"""
@@ -399,7 +399,7 @@ def example(event: identity_fn.AuthBlockingEvent) -> identity_fn.BeforeCreateRes
399399
:param \\*\\*kwargs: Options.
400400
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BlockingOptions`
401401
:rtype: :exc:`typing.Callable`
402-
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
402+
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
403403
:exc:`firebase_functions.identity_fn.BeforeCreateResponse` \\| `None` \\]
404404
A function that takes a AuthBlockingEvent and optionally returns BeforeCreateResponse.
405405
"""

src/firebase_functions/private/_alerts_fn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
"""Internal utilities for Firebase Alert function types."""
1515

16-
# pylint: disable=protected-access
16+
# pylint: disable=protected-access,cyclic-import
1717
import typing as _typing
1818
import datetime as _dt
1919
import cloudevents.http as _ce

src/firebase_functions/private/_identity_fn.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ 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-
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),
72-
)
67+
creation_time = _dt.datetime.utcfromtimestamp(
68+
int(token_data["creation_time"]) / 1000.0)
69+
last_sign_in_time = None
70+
if "last_sign_in_time" in token_data:
71+
last_sign_in_time = _dt.datetime.utcfromtimestamp(
72+
int(token_data["last_sign_in_time"]) / 1000.0)
73+
74+
return AuthUserMetadata(creation_time=creation_time,
75+
last_sign_in_time=last_sign_in_time)
7376

7477

7578
def _auth_multi_factor_info_from_token_data(token_data: dict[str, _typing.Any]):

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,

src/firebase_functions/private/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _on_call_valid_body(request: _Request) -> bool:
123123
}
124124
if len(extra_keys) != 0:
125125
_logging.warning(
126-
"Request body has extra fields: ",
126+
"Request body has extra fields: %s",
127127
"".join(f"{key}: {value}," for (key, value) in extra_keys.items()),
128128
)
129129
return False
@@ -156,7 +156,7 @@ def _on_call_valid_content_type(request: _Request) -> bool:
156156

157157
# Check that the Content-Type is JSON.
158158
if content_type.lower() != "application/json":
159-
_logging.warning("Request has incorrect Content-Type.", content_type)
159+
_logging.warning("Request has incorrect Content-Type: %s", content_type)
160160
return False
161161

162162
return True
@@ -273,7 +273,7 @@ def on_call_check_tokens(request: _Request,) -> _OnCallTokenVerification:
273273
errs.append(("Auth token was rejected.", log_payload))
274274

275275
if len(errs) == 0:
276-
_logging.info("Callable request verification passed", log_payload)
276+
_logging.info("Callable request verification passed: %s", log_payload)
277277
else:
278278
_logging.warning(f"Callable request verification failed: ${errs}",
279279
log_payload)

0 commit comments

Comments
 (0)