firebase_functions.identity_fn module

Cloud functions to handle Eventarc events.

Classes

AdditionalUserInfo

classfirebase_functions.identity_fn.AdditionalUserInfo(provider_id:str,profile:dict[str,Any]|None,username:str|None,is_new_user:bool,recaptcha_score:float|None)

Bases:object

The additional user info component of the auth event context.

is_new_user:bool

A boolean indicating if the user is new or not.

profile:dict[str,Any]|None

The user's profile data as a dictionary.

provider_id:str

The provider identifier.

recaptcha_score:float|None

The user's reCAPTCHA score, if available.

username:str|None

The user's username, if available.

AuthBlockingEvent

classfirebase_functions.identity_fn.AuthBlockingEvent(data:AuthUserRecord,locale:str|None,event_id:str,ip_address:str,user_agent:str,additional_user_info:AdditionalUserInfo,credential:Credential|None,timestamp:datetime)

Bases:object

Defines an auth event for identitytoolkit v2 auth blocking events.

additional_user_info:AdditionalUserInfo

An object containing information about the user.

credential:Credential|None

An object containing information about the user's credential.

data:AuthUserRecord

The UserRecord passed to auth blocking functions from the identity platform.

event_id:str

The event's unique identifier.Example: 'rWsyPtolplG2TBFoOkkgyg'

ip_address:str

The IP address of the device the end user is registering or signing in from.Example: '114.14.200.1'

locale:str|None

The application locale. You can set the locale using the client SDK,or by passing the locale header in the REST API.Example: 'fr' or 'sv-SE'

timestamp:datetime

The time the event was triggered.

user_agent:str

The user agent triggering the blocking function.Example: 'Mozilla/5.0 (X11; Linux x86_64)'

AuthMultiFactorInfo

classfirebase_functions.identity_fn.AuthMultiFactorInfo(uid:str,display_name:str|None,factor_id:str,enrollment_time:datetime|None,phone_number:str|None)

Bases:object

Interface representing the common properties of a user-enrolled second factor.

display_name:str|None

The optional display name of the enrolled second factor.

enrollment_time:datetime|None

The optional date the second factor was enrolled.

factor_id:str

The type identifier of the second factor. For SMS second factors, this isphone.

phone_number:str|None

The phone number associated with a phone second factor.

uid:str

The ID of the enrolled second factor. This ID is unique to the user.

AuthMultiFactorSettings

classfirebase_functions.identity_fn.AuthMultiFactorSettings(enrolled_factors:list[AuthMultiFactorInfo])

Bases:object

The multi-factor related properties for the current user, if available.

enrolled_factors:list[AuthMultiFactorInfo]

List of second factors enrolled with the current user.

AuthUserInfo

classfirebase_functions.identity_fn.AuthUserInfo(uid:str,provider_id:str,display_name:str|None=None,email:str|None=None,photo_url:str|None=None,phone_number:str|None=None)

Bases:object

User info that is part of the AuthUserRecord.

display_name:str|None=None

The display name for the linked provider.

email:str|None=None

The email for the linked provider.

phone_number:str|None=None

The phone number for the linked provider.

photo_url:str|None=None

The photo URL for the linked provider.

provider_id:str

The linked provider ID (such as "google.com" for the Google provider).

uid:str

The user identifier for the linked provider.

AuthUserMetadata

classfirebase_functions.identity_fn.AuthUserMetadata(creation_time:datetime,last_sign_in_time:datetime|None)

Bases:object

Additional metadata about the user.

creation_time:datetime

The date the user was created.

last_sign_in_time:datetime|None

The date the user last signed in.

AuthUserRecord

classfirebase_functions.identity_fn.AuthUserRecord(uid:str,email:str|None,email_verified:bool|None,display_name:str|None,photo_url:str|None,phone_number:str|None,disabled:bool,metadata:AuthUserMetadata,provider_data:list[AuthUserInfo],password_hash:str|None,password_salt:str|None,custom_claims:dict[str,Any]|None,tenant_id:str|None,tokens_valid_after_time:datetime|None,multi_factor:AuthMultiFactorSettings|None)

Bases:object

The UserRecord passed to auth blocking functions from the identity platform.

custom_claims:dict[str,Any]|None

The user's custom claims object if available.

disabled:bool

true for disabled;false for enabled.

Type:

Whether or not the user is disabled

display_name:str|None

The user's display name.

email:str|None

The user's primary email, if set.

email_verified:bool|None

Whether or not the user's primary email is verified.

metadata:AuthUserMetadata

Additional metadata about the user.

multi_factor:AuthMultiFactorSettings|None

The multi-factor related properties for the current user, if available.

password_hash:str|None

The user's hashed password (base64-encoded).

password_salt:str|None

The user's password salt (base64-encoded).

phone_number:str|None

The user's primary phone number, if set.

photo_url:str|None

The user's photo URL.

provider_data:list[AuthUserInfo]

An array of providers (such as Google or Facebook) linked to the user.

tenant_id:str|None

The ID of the tenant the user belongs to, if available.

tokens_valid_after_time:datetime|None

The date the user's tokens are valid after.

uid:str

The user'suid.

BeforeCreateResponse

classfirebase_functions.identity_fn.BeforeCreateResponse

Bases:TypedDict

The handler response type for 'before_user_created' blocking events.

custom_claims:dict[str,Any]|None

The user's custom claims object if available.

disabled:bool|None

Whether or not the user is disabled.

display_name:str|None

The user's display name.

email_verified:bool|None

Whether or not the user's primary email is verified.

photo_url:str|None

The user's photo URL.

recaptcha_action_override:Literal['ALLOW','BLOCK']|None

BeforeSignInResponse

classfirebase_functions.identity_fn.BeforeSignInResponse

Bases:dict

The handler response type for 'before_user_signed_in' blocking events.

custom_claims:dict[str,Any]|None
disabled:bool|None
display_name:str|None
email_verified:bool|None
photo_url:str|None
recaptcha_action_override:Literal['ALLOW','BLOCK']|None
session_claims:dict[str,Any]|None

The user's session claims object if available.

Credential

classfirebase_functions.identity_fn.Credential(claims:dict[str,Any]|None,id_token:str|None,access_token:str|None,refresh_token:str|None,expiration_time:datetime|None,secret:str|None,provider_id:str,sign_in_method:str)

Bases:object

The credential component of the auth event context.

access_token:str|None

The user's access token.

claims:dict[str,Any]|None

The user's claims data as a dictionary.

expiration_time:datetime|None

The expiration time of the user's access token.

id_token:str|None

The user's ID token.

provider_id:str

The provider identifier.

refresh_token:str|None

The user's refresh token.

secret:str|None

The user's secret.

sign_in_method:str

The user's sign-in method.

Functions

before_user_created

firebase_functions.identity_fn.before_user_created(**kwargs)Callable[[Callable[[AuthBlockingEvent],BeforeCreateResponse|None]],Callable[[AuthBlockingEvent],BeforeCreateResponse|None]]

Handles an event that is triggered before a user is created.

Example:

fromfirebase_functionsimportidentity_fn@identity_fn.before_user_created()defexample(event:identity_fn.AuthBlockingEvent)->identity_fn.BeforeCreateResponse|None:pass
Parameters:

**kwargs (asfirebase_functions.options.BlockingOptions) -- Options.

Return type:

typing.Callable[ [firebase_functions.identity_fn.AuthBlockingEvent ],firebase_functions.identity_fn.BeforeCreateResponse |None ]A function that takes a AuthBlockingEvent and optionally returns BeforeCreateResponse.

before_user_signed_in

firebase_functions.identity_fn.before_user_signed_in(**kwargs)Callable[[Callable[[AuthBlockingEvent],BeforeSignInResponse|None]],Callable[[AuthBlockingEvent],BeforeSignInResponse|None]]

Handles an event that is triggered before a user is signed in.

Example:

fromfirebase_functionsimportidentity_fn@identity_fn.before_user_signed_in()defexample(event:identity_fn.AuthBlockingEvent)->identity_fn.BeforeSignInResponse|None:pass
Parameters:

**kwargs (asfirebase_functions.options.BlockingOptions) -- Options.

Return type:

typing.Callable[ [firebase_functions.identity_fn.AuthBlockingEvent ],firebase_functions.identity_fn.BeforeSignInResponse |None ]A function that takes a AuthBlockingEvent and optionally returns BeforeSignInResponse.

Constants

BeforeUserCreatedCallable

firebase_functions.identity_fn.BeforeUserCreatedCallable

The type of the callable for 'before_user_created' blocking events.

alias ofCallable[[AuthBlockingEvent],BeforeCreateResponse |None]

BeforeUserSignedInCallable

firebase_functions.identity_fn.BeforeUserSignedInCallable

The type of the callable for 'before_user_signed_in' blocking events.

alias ofCallable[[AuthBlockingEvent],BeforeSignInResponse |None]

RecaptchaActionOptions

firebase_functions.identity_fn.RecaptchaActionOptions

The reCAPTCHA action options.

alias ofLiteral['ALLOW', 'BLOCK']

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-20 UTC.