How to extract event_type from AuthBlockingEvent dataclass firebase cloud function

60 Views Asked by At

I would like to extract the associated sign-in method used, like Google or email/password from the event.

Given the Google Documentations here for Getting user and context information, some fields are not available on the AuthBlockingEvent dataclass.

For example I can extract the following:

from firebase_functions import https_fn, identity_fn, options

@identity_fn.before_user_signed_in()
def handle_user(
    event: identity_fn.AuthBlockingEvent,
) -> identity_fn.BeforeSignInResponse | None:
    email = event.data.email
    uid = event.data.uid
    event_id = event.event_id
    event_type = event.credential

However, the following does on exist on the even signature.

from firebase_functions import https_fn, identity_fn, options

@identity_fn.before_user_signed_in()
def handle_user(
    event: identity_fn.AuthBlockingEvent,
) -> identity_fn.BeforeSignInResponse | None:
    event_type = event.event_type
    auth_type = event.auth_type
    resource = event.resource
    # etc

I also opened an issue on the official repository https://github.com/firebase/firebase-functions-python/issues/180

1

There are 1 best solutions below

0
axelmukwena On

I was able to get the information I wanted through additional_user_info.provider_id which can have a value of google.com, password, etc. depending on how the user is signing in.

On firebase Blocking functions, if you set any of the Additional provider token credentials, you can also access event.credential.sign_in_method which can also have a value of google.com, password, etc.

@identity_fn.before_user_signed_in()
def handle_user(
    event: identity_fn.AuthBlockingEvent,
) -> identity_fn.BeforeSignInResponse | None:
    sign_in_provider = event.additional_user_info.provider_id
    sign_in_method = event.credential.sign_in_method if event.credential else None