Skip to content

Commit a4b105c

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

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/firebase_functions/identity_fn.py

+27-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
@@ -237,18 +238,21 @@ class Credential:
237238
sign_in_method: str
238239
"""The user's sign-in method."""
239240

241+
class EmailType(str, Enum):
242+
EMAIL_SIGN_IN = "EMAIL_SIGN_IN"
243+
PASSWORD_RESET = "PASSWORD_RESET"
244+
245+
class SmsType(str, Enum):
246+
SIGN_IN_OR_SIGN_UP = "SIGN_IN_OR_SIGN_UP"
247+
MULTI_FACTOR_SIGN_IN = "MULTI_FACTOR_SIGN_IN"
248+
MULTI_FACTOR_ENROLLMENT = "MULTI_FACTOR_ENROLLMENT"
240249

241250
@_dataclasses.dataclass(frozen=True)
242251
class AuthBlockingEvent:
243252
"""
244253
Defines an auth event for identitytoolkit v2 auth blocking events.
245254
"""
246255

247-
data: AuthUserRecord
248-
"""
249-
The UserRecord passed to auth blocking functions from the identity platform.
250-
"""
251-
252256
locale: str | None
253257
"""
254258
The application locale. You can set the locale using the client SDK,
@@ -262,6 +266,13 @@ class AuthBlockingEvent:
262266
Example: 'rWsyPtolplG2TBFoOkkgyg'
263267
"""
264268

269+
event_type: str
270+
"""
271+
The event type. This provides information on the event name, such as
272+
beforeSignIn or beforeCreate, and the associated sign-in method used,
273+
like Google or email/password.
274+
"""
275+
265276
ip_address: str
266277
"""
267278
The IP address of the device the end user is registering or signing in from.
@@ -280,10 +291,21 @@ class AuthBlockingEvent:
280291
credential: Credential | None
281292
"""An object containing information about the user's credential."""
282293

294+
email_type: EmailType | None
295+
"""The type of email event."""
296+
297+
sms_type: SmsType | None
298+
"""The type of SMS event."""
299+
283300
timestamp: _dt.datetime
284301
"""
285302
The time the event was triggered."""
286303

304+
data: AuthUserRecord
305+
"""
306+
The UserRecord passed to auth blocking functions from the identity platform.
307+
"""
308+
287309

288310
RecaptchaActionOptions = _typing.Literal["ALLOW", "BLOCK"]
289311
"""

src/firebase_functions/private/_identity_fn.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,20 @@ 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, token_data: dict[str, _typing.Any]):
204204
from firebase_functions.identity_fn import AuthBlockingEvent
205205
return AuthBlockingEvent(
206206
data=_auth_user_record_from_token_data(token_data["user_record"]),
207207
locale=token_data.get("locale"),
208+
event_type=event_type,
208209
event_id=token_data["event_id"],
209210
ip_address=token_data["ip_address"],
210211
user_agent=token_data["user_agent"],
211212
timestamp=_dt.datetime.fromtimestamp(token_data["iat"]),
212213
additional_user_info=_additional_user_info_from_token_data(token_data),
213214
credential=_credential_from_token_data(token_data, _time.time()),
215+
email_type=token_data.get("email_type"),
216+
sms_type=token_data.get("sms_type"),
214217
)
215218

216219

@@ -351,7 +354,7 @@ def before_operation_handler(
351354
raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request")
352355
jwt_token = request.json["data"]["jwt"]
353356
decoded_token = _token_verifier.verify_auth_blocking_token(jwt_token)
354-
event = _auth_blocking_event_from_token_data(decoded_token)
357+
event = _auth_blocking_event_from_token_data(event_type, decoded_token)
355358
auth_response: BeforeCreateResponse | BeforeSignInResponse | None = _with_init(
356359
func)(event)
357360
if not auth_response:

0 commit comments

Comments
 (0)