Skip to content

Commit 779dd85

Browse files
committed
fix(identity): AuthBlockingEvent properties not matching docs
1 parent e1110eb commit 779dd85

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

Diff for: src/firebase_functions/identity_fn.py

+30-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import functools as _functools
1919
import datetime as _dt
2020
import dataclasses as _dataclasses
21+
from enum import Enum
2122

2223
import firebase_functions.options as _options
2324
import firebase_functions.private.util as _util
@@ -238,17 +239,23 @@ class Credential:
238239
"""The user's sign-in method."""
239240

240241

242+
class EmailType(str, Enum):
243+
EMAIL_SIGN_IN = "EMAIL_SIGN_IN"
244+
PASSWORD_RESET = "PASSWORD_RESET"
245+
246+
247+
class SmsType(str, Enum):
248+
SIGN_IN_OR_SIGN_UP = "SIGN_IN_OR_SIGN_UP"
249+
MULTI_FACTOR_SIGN_IN = "MULTI_FACTOR_SIGN_IN"
250+
MULTI_FACTOR_ENROLLMENT = "MULTI_FACTOR_ENROLLMENT"
251+
252+
241253
@_dataclasses.dataclass(frozen=True)
242254
class AuthBlockingEvent:
243255
"""
244256
Defines an auth event for identitytoolkit v2 auth blocking events.
245257
"""
246258

247-
data: AuthUserRecord
248-
"""
249-
The UserRecord passed to auth blocking functions from the identity platform.
250-
"""
251-
252259
locale: str | None
253260
"""
254261
The application locale. You can set the locale using the client SDK,
@@ -262,6 +269,13 @@ class AuthBlockingEvent:
262269
Example: 'rWsyPtolplG2TBFoOkkgyg'
263270
"""
264271

272+
event_type: str
273+
"""
274+
The event type. This provides information on the event name, such as
275+
beforeSignIn or beforeCreate, and the associated sign-in method used,
276+
like Google or email/password.
277+
"""
278+
265279
ip_address: str
266280
"""
267281
The IP address of the device the end user is registering or signing in from.
@@ -280,10 +294,21 @@ class AuthBlockingEvent:
280294
credential: Credential | None
281295
"""An object containing information about the user's credential."""
282296

297+
email_type: EmailType | None
298+
"""The type of email event."""
299+
300+
sms_type: SmsType | None
301+
"""The type of SMS event."""
302+
283303
timestamp: _dt.datetime
284304
"""
285305
The time the event was triggered."""
286306

307+
data: AuthUserRecord
308+
"""
309+
The UserRecord passed to auth blocking functions from the identity platform.
310+
"""
311+
287312

288313
RecaptchaActionOptions = _typing.Literal["ALLOW", "BLOCK"]
289314
"""

Diff for: src/firebase_functions/private/_identity_fn.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,21 @@ def _credential_from_token_data(token_data: dict[str, _typing.Any],
200200
)
201201

202202

203-
def _auth_blocking_event_from_token_data(token_data: dict[str, _typing.Any]):
203+
def _auth_blocking_event_from_token_data(event_type: str,
204+
token_data: dict[str, _typing.Any]):
204205
from firebase_functions.identity_fn import AuthBlockingEvent
205206
return AuthBlockingEvent(
206207
data=_auth_user_record_from_token_data(token_data["user_record"]),
207208
locale=token_data.get("locale"),
209+
event_type=event_type,
208210
event_id=token_data["event_id"],
209211
ip_address=token_data["ip_address"],
210212
user_agent=token_data["user_agent"],
211213
timestamp=_dt.datetime.fromtimestamp(token_data["iat"]),
212214
additional_user_info=_additional_user_info_from_token_data(token_data),
213215
credential=_credential_from_token_data(token_data, _time.time()),
216+
email_type=token_data.get("email_type"),
217+
sms_type=token_data.get("sms_type"),
214218
)
215219

216220

@@ -351,7 +355,7 @@ def before_operation_handler(
351355
raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request")
352356
jwt_token = request.json["data"]["jwt"]
353357
decoded_token = _token_verifier.verify_auth_blocking_token(jwt_token)
354-
event = _auth_blocking_event_from_token_data(decoded_token)
358+
event = _auth_blocking_event_from_token_data(event_type, decoded_token)
355359
auth_response: BeforeCreateResponse | BeforeSignInResponse | None = _with_init(
356360
func)(event)
357361
if not auth_response:

0 commit comments

Comments
 (0)