Skip to content

Authentication reference

At a glance

Auth

Member Notes
Auth.auth() The shared instance
current_user A User, or None
add_state_did_change_listener(listener) / add_id_token_did_change_listener(listener) listener(user); returns an AuthStateListener (.remove())
sign_in_with_email_password(email, password, cb) / create_user_with_email_password(...) cb(AuthDataResult, error)
sign_in_anonymously(cb), sign_in_with_custom_token(token, cb)
sign_in_with_credential(credential, cb), sign_in_with_provider(OAuthProvider, cb)
send_sign_in_link(email, settings, cb), is_sign_in_with_email_link(link), sign_in_with_email_link(email, link, cb) Passwordless
send_password_reset(email, cb, settings), verify_password_reset_code(code, cb), confirm_password_reset(code, password, cb)
check_action_code(code, cb), apply_action_code(code, cb) cb(ActionCodeInfo, error) / cb(error)
sign_out(), update_current_user(user, cb), revoke_token(code, cb)
get_stored_user(access_group) (user, error): the user in a shared keychain
use_emulator(host, port), is_using_emulator, language_code, use_app_language(), tenant_id, app_verification_disabled_for_testing, use_user_access_group(group) Settings
can_handle_url(url), can_handle_notification(user_info), set_apns_token(token, type) App delegate hooks (phone, OAuth)

User

  • Profile: uid, email, display_name, phone_number, photo_url, provider_id, is_anonymous, is_email_verified, provider_data (list of UserInfo), metadata (UserMetadata: creation_date, last_sign_in_date), tenant_id, refresh_token, is_signed_in
  • Tokens: get_id_token(cb, force_refresh=False), get_id_token_result(cb, force_refresh=False) → IDTokenResult (token, claims, expiration_date, issued_at_date, auth_date, sign_in_provider, sign_in_second_factor)
  • Account: reload, delete, update_password, update_email, update_profile(cb, *, display_name, photo_url), update_phone_number, send_email_verification, send_email_verification_before_updating_email
  • Providers: link_with_credential, link_with_provider, unlink, reauthenticate_with_credential, reauthenticate_with_provider

Credentials and providers

Provider Make a credential
EmailAuthProvider credential(email, password), credential_with_link(email, link)
GoogleAuthProvider credential(id_token, access_token) (or auth.google)
OAuthProvider OAuthProvider(id, scopes, custom_parameters) for web flows; credential(id, id_token, access_token, raw_nonce); apple_credential(id_token, raw_nonce, given_name, family_name) (or auth.apple)
PhoneAuthProvider verify_phone_number(number, cb), then credential(verification_id, code)
FacebookAuthProvider credential(access_token)
GitHubAuthProvider credential(token)
TwitterAuthProvider credential(token, secret)
GameCenterAuthProvider get_credential(cb)

Each has a PROVIDER_ID. AuthDataResult has user, additional_user_info (provider_id, is_new_user, username, profile) and credential.

Multi-factor

  • User.multi_factor → MultiFactor: enrolled_factors, get_session(cb), enroll(assertion, display_name, cb), unenroll(factor_or_uid, cb)
  • MultiFactorInfo (uid, factor_id, display_name, enrollment_date), PhoneMultiFactorInfo (+ phone_number)
  • PhoneMultiFactorGenerator.assertion(credential); PhoneAuthProvider.verify_phone_number(..., multi_factor_session=), verify_phone_number_for_sign_in(hint, session, cb)
  • TOTPMultiFactorGenerator.generate_secret(session, cb), assertion_for_enrollment(secret, code), assertion_for_sign_in(enrollment_id, code); TOTPSecret.shared_secret_key(), generate_qr_code_url(account, issuer), open_in_otp_app(url)
  • MultiFactorResolver (from AuthError.resolver): hints, session, resolve_sign_in(assertion, cb)

Facebook (pyios_firebase.auth.facebook)

initialize_facebook(), start_facebook_sign_in(cb, permissions, limited), get_facebook_credential(cb, permissions, limited), sign_out_of_facebook(), on_facebook_handle_url(url), on_facebook_handle_url_kivy(...)

Errors

AuthError (keys above, plus resolver for SECOND_FACTOR_REQUIRED) and AuthErrorCode: every FIRAuthErrorCode of the SDK, by name (EMAIL_ALREADY_IN_USE, WRONG_PASSWORD, REQUIRES_RECENT_LOGIN, ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL, ...).

pyios_firebase.auth

Firebase Authentication.

from pyios_firebase.auth import Auth

auth = Auth.auth()
auth.create_user_with_email_password("ada@example.com", "s3cret!", on_signed_in)
listener = auth.add_state_did_change_listener(lambda user: print("user:", user))
  • Auth: sign-in (email/password, email link, anonymous, custom token, credentials, OAuth web flows), sign-out, listeners, password reset and action codes, the emulator
  • User: profile, ID tokens and claims, account changes, email verification, linking and re-authentication
  • credentials: EmailAuthProvider, GoogleAuthProvider, OAuthProvider (Apple, Microsoft, Yahoo, GitHub, OIDC, SAML), PhoneAuthProvider, FacebookAuthProvider, GitHubAuthProvider, TwitterAuthProvider, GameCenterAuthProvider
  • pyios_firebase.auth.google / pyios_firebase.auth.apple: the Google and Apple sign-in sheets
  • multi-factor (pyios_firebase.auth.multi_factor): SMS and TOTP second factors
  • AuthError / AuthErrorCode: what failed

Needs the FirebaseAuth framework. Google sign-in also needs GoogleSignIn; Apple sign-in needs the com.apple.developer.applesignin entitlement.

Modules:

Name Description
apple

Sign in with Apple, then Firebase Auth.

auth

Auth: Firebase Authentication for the app. Sign-in, sign-out, listeners,

credentials

Sign-in credentials and the providers that make them.

errors

Firebase Authentication errors.

facebook

Facebook Login, then Firebase Auth.

google

Google Sign-In, then Firebase Auth.

multi_factor

Multi-factor authentication: SMS and TOTP (authenticator app) second factors.

results

What Firebase Authentication calls give back, as plain Python values.

user

User: a Firebase user, with their profile, tokens and account actions.

Classes:

Name Description
Auth

Firebase Authentication. Get it with Auth.auth().

AuthStateListener

Given back by add_state_did_change_listener and

AuthCredential

A sign-in credential for one provider.

EmailAuthProvider

Credentials for email and password, or email link, sign-in.

FacebookAuthProvider

Credentials from Facebook Login access tokens.

GameCenterAuthProvider

Credentials for the Game Center player signed in on the device.

GitHubAuthProvider

Credentials from GitHub OAuth access tokens (for the web flow, use

GoogleAuthProvider

Credentials from Google Sign-In tokens. For the whole flow, see

OAuthCredential

A credential from an OAuth provider (Apple, Microsoft, Yahoo, ...).

OAuthProvider

A generic OAuth provider: Apple, Microsoft, Yahoo, GitHub, or any OIDC /

PhoneAuthProvider

Phone number sign-in: send a code by SMS, then make a credential from it.

TwitterAuthProvider

Credentials from Twitter (X) OAuth 1.0 tokens.

AuthError

An error from Firebase Authentication (or from a sign-in sheet).

AuthErrorCode

The error.code values of Firebase Authentication errors.

MultiFactor

A user's second factors. Get it with User.multi_factor.

MultiFactorAssertion

Proof of a second factor, for MultiFactor.enroll or

MultiFactorInfo

One enrolled second factor.

MultiFactorResolver

Finishes a sign-in that needs a second factor. Get it from

MultiFactorSession

Proves the first factor was just completed (or that the user is signed

PhoneMultiFactorGenerator

Make SMS second-factor assertions.

PhoneMultiFactorInfo

An enrolled SMS second factor.

TOTPMultiFactorGenerator

Make TOTP (authenticator app) secrets and assertions.

TOTPSecret

A new TOTP secret, to show to the user while they set up their

ActionCodeInfo

What Auth.check_action_code learned about an email action code.

ActionCodeOperation

What an email action code (link) is for. The values of

ActionCodeSettings

Where email links (password reset, verification, sign-in) lead.

ActionCodeURL

The parts of an email action link (password reset, verification,

AdditionalUserInfo

Provider details from one sign-in.

AuthDataResult

The result of a sign-in, link or re-authentication.

IDTokenResult

A Firebase ID token and what it says.

UserInfo

A user's profile at one provider (an entry of User.provider_data).

UserMetadata

When the user was created and last signed in.

User

A Firebase user: the signed-in one by default.

Functions:

Name Description
current_user

The signed-in User, or None. Same as Auth.auth().current_user.

sign_out

Sign the current user out of Firebase. Same as Auth.auth().sign_out().

Attributes:

Name Type Description
APNS_TOKEN_TYPE_PRODUCTION Final

set_apns_token type: a production APNs token.

APNS_TOKEN_TYPE_SANDBOX Final

set_apns_token type: a development (sandbox) APNs token.

APNS_TOKEN_TYPE_UNKNOWN Final

set_apns_token type: let Firebase find out (sandbox or production).

AUTH_ERROR_DOMAIN Final

The error.domain of Firebase Authentication errors.

PHONE_FACTOR_ID Final

The factor_id of SMS second factors.

TOTP_FACTOR_ID Final

The factor_id of TOTP (authenticator app) second factors.

UNSET Final

Leave this profile field as it is (update_profile).

APNS_TOKEN_TYPE_PRODUCTION module-attribute

APNS_TOKEN_TYPE_PRODUCTION: Final = 2

set_apns_token type: a production APNs token.

APNS_TOKEN_TYPE_SANDBOX module-attribute

APNS_TOKEN_TYPE_SANDBOX: Final = 1

set_apns_token type: a development (sandbox) APNs token.

APNS_TOKEN_TYPE_UNKNOWN module-attribute

APNS_TOKEN_TYPE_UNKNOWN: Final = 0

set_apns_token type: let Firebase find out (sandbox or production).

AUTH_ERROR_DOMAIN module-attribute

AUTH_ERROR_DOMAIN: Final = 'FIRAuthErrorDomain'

The error.domain of Firebase Authentication errors.

PHONE_FACTOR_ID module-attribute

PHONE_FACTOR_ID: Final = 'phone'

The factor_id of SMS second factors.

TOTP_FACTOR_ID module-attribute

TOTP_FACTOR_ID: Final = 'totp'

The factor_id of TOTP (authenticator app) second factors.

UNSET module-attribute

UNSET: Final = _Unset()

Leave this profile field as it is (update_profile).

Auth

Auth(native: ObjCObject | None = None)

Firebase Authentication. Get it with Auth.auth().

::

auth = Auth.auth()
auth.sign_in_with_email_password("ada@example.com", "s3cret!", on_signed_in)

Every callback gets (result, error) (or just (error)), where error is an AuthError or None.

Parameters:

Name Type Description Default
native ObjCObject | None

the native FIRAuth. Leave it out for the default app's.

None

Methods:

Name Description
auth

The shared Auth for the default Firebase app.

update_current_user

Make user the signed-in user (for example one from another

sign_out

Sign the current user out of Firebase (Google, Apple and other

sign_in_with_email_password

Sign in with an email address and password.

create_user_with_email_password

Create an account with an email address and password, and sign in.

sign_in_anonymously

Sign in as a new anonymous user (or the current anonymous one).

sign_in_with_custom_token

Sign in with a custom token made by your backend (Admin SDK

sign_in_with_credential

Sign in with a credential from any provider.

sign_in_with_provider

Sign in through an OAuth provider's web flow (Microsoft, Yahoo,

send_sign_in_link

Email a passwordless sign-in link.

is_sign_in_with_email_link

Whether link (a URL the app was opened with) is a sign-in link.

sign_in_with_email_link

Sign in with an email link from send_sign_in_link.

send_password_reset

Email a password reset link.

verify_password_reset_code

Check a password reset code (the oobCode of the link).

confirm_password_reset

Set a new password with a password reset code.

check_action_code

Find out what an email action code is for, without using it.

apply_action_code

Use an email action code: verify an email address, or recover / change one.

fetch_sign_in_methods

The sign-in methods used with email.

revoke_token

Revoke a Sign in with Apple token, before deleting an Apple user

add_state_did_change_listener

Listen to sign-in and sign-out.

add_id_token_did_change_listener

Listen to sign-in, sign-out and ID token refreshes (about once an

use_emulator

Send this app's Auth calls to the local Auth emulator.

use_app_language

Set language_code to the app's current language.

use_user_access_group

Share the signed-in user with other apps (and extensions) through a

get_stored_user

The user saved in a keychain access group, without switching to it

can_handle_url

Give a URL the app was opened with to Firebase Auth (reCAPTCHA and

can_handle_notification

Give a remote notification to Firebase Auth (silent push for phone

set_apns_token

Give Firebase Auth the app's APNs device token (phone sign-in).

Attributes:

Name Type Description
native ObjCObject

The FIRAuth, for SDK calls this wrapper does not cover.

current_user User | None

The signed-in user, or None.

is_using_emulator bool

True after use_emulator.

language_code str | None

The language of emails, SMS and web flows Firebase sends, for

tenant_id str | None

The tenant users sign in to (multi-tenancy with Identity Platform),

app_verification_disabled_for_testing bool

Skip app verification for phone sign-in with test numbers (set in

native property

native: ObjCObject

The FIRAuth, for SDK calls this wrapper does not cover.

current_user property

current_user: User | None

The signed-in user, or None.

Right after app start this can be None for a moment while Firebase restores the saved user; use add_state_did_change_listener to know for sure.

is_using_emulator property

is_using_emulator: bool

True after use_emulator.

language_code property writable

language_code: str | None

The language of emails, SMS and web flows Firebase sends, for example "fr"; None for the project default.

tenant_id property writable

tenant_id: str | None

The tenant users sign in to (multi-tenancy with Identity Platform), or None.

app_verification_disabled_for_testing property writable

app_verification_disabled_for_testing: bool

Skip app verification for phone sign-in with test numbers (set in the Firebase console). For tests only.

auth classmethod

auth() -> Auth

The shared Auth for the default Firebase app.

update_current_user

update_current_user(
    user: User, callback: ErrorCallback | None = None
) -> None

Make user the signed-in user (for example one from another Auth instance or a shared keychain).

Parameters:

Name Type Description Default
user User

the user to sign in as.

required
callback ErrorCallback | None

gets None or the error.

None

sign_out

sign_out() -> AuthError | None

Sign the current user out of Firebase (Google, Apple and other providers keep their own sessions).

Returns:

Type Description
AuthError | None

None, or the error (for example a keychain error).

sign_in_with_email_password

sign_in_with_email_password(
    email: str,
    password: str,
    callback: DataResultCallback | None = None,
) -> None

Sign in with an email address and password.

Parameters:

Name Type Description Default
email str

the email address.

required
password str

the password.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error). With email enumeration protection (the default), a wrong email or password both give INVALID_CREDENTIAL.

None

create_user_with_email_password

create_user_with_email_password(
    email: str,
    password: str,
    callback: DataResultCallback | None = None,
) -> None

Create an account with an email address and password, and sign in.

Parameters:

Name Type Description Default
email str

the email address.

required
password str

the password (at least 6 characters, or your project's password policy).

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error) (EMAIL_ALREADY_IN_USE, WEAK_PASSWORD, INVALID_EMAIL...).

None

sign_in_anonymously

sign_in_anonymously(
    callback: DataResultCallback | None = None,
) -> None

Sign in as a new anonymous user (or the current anonymous one).

Link a credential later (User.link_with_credential) to keep the account when the user signs up.

Parameters:

Name Type Description Default
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error).

None

sign_in_with_custom_token

sign_in_with_custom_token(
    token: str, callback: DataResultCallback | None = None
) -> None

Sign in with a custom token made by your backend (Admin SDK create_custom_token).

Parameters:

Name Type Description Default
token str

the custom token.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error) (INVALID_CUSTOM_TOKEN, CUSTOM_TOKEN_MISMATCH).

None

sign_in_with_credential

sign_in_with_credential(
    credential: AuthCredential,
    callback: DataResultCallback | None = None,
) -> None

Sign in with a credential from any provider.

Parameters:

Name Type Description Default
credential AuthCredential

the credential, from one of the provider classes.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error). ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL means the email is already used with another provider: sign in with that one, then link this credential.

None

sign_in_with_provider

sign_in_with_provider(
    provider: OAuthProvider,
    callback: DataResultCallback | None = None,
) -> None

Sign in through an OAuth provider's web flow (Microsoft, Yahoo, GitHub, OIDC, SAML), in an in-app browser.

Parameters:

Name Type Description Default
provider OAuthProvider

the provider, for example OAuthProvider("yahoo.com").

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error). error.cancelled is True when the user closed the browser. If the callback URL scheme is missing from Info.plist, the error says which one to add (the SDK itself would stop the app).

None
send_sign_in_link(
    email: str,
    action_code_settings: ActionCodeSettings,
    callback: ErrorCallback | None = None,
) -> None

Email a passwordless sign-in link.

Save email on the device: you need it again in sign_in_with_email_link.

Parameters:

Name Type Description Default
email str

where to send the link.

required
action_code_settings ActionCodeSettings

where the link leads; handle_code_in_app must be True.

required
callback ErrorCallback | None

gets None once the email is sent, or the error.

None
is_sign_in_with_email_link(link: str) -> bool

Whether link (a URL the app was opened with) is a sign-in link.

Parameters:

Name Type Description Default
link str

the full URL.

required

Returns:

Type Description
bool

True if it can be passed to sign_in_with_email_link.

sign_in_with_email_link(
    email: str,
    link: str,
    callback: DataResultCallback | None = None,
) -> None

Sign in with an email link from send_sign_in_link.

Parameters:

Name Type Description Default
email str

the address the link was sent to.

required
link str

the full link the user opened.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error) (INVALID_ACTION_CODE / EXPIRED_ACTION_CODE).

None

send_password_reset

send_password_reset(
    email: str,
    callback: ErrorCallback | None = None,
    action_code_settings: ActionCodeSettings | None = None,
) -> None

Email a password reset link.

Parameters:

Name Type Description Default
email str

the account's email address.

required
callback ErrorCallback | None

gets None once the email is sent, or the error. With email enumeration protection on, an unknown address is not an error.

None
action_code_settings ActionCodeSettings | None

where the link leads, or None for the Firebase default page.

None

verify_password_reset_code

verify_password_reset_code(
    code: str,
    callback: Callable[
        [str | None, AuthError | None], None
    ],
) -> None

Check a password reset code (the oobCode of the link).

Parameters:

Name Type Description Default
code str

the code.

required
callback Callable[[str | None, AuthError | None], None]

gets (email, None) with the account's address, or (None, error).

required

confirm_password_reset

confirm_password_reset(
    code: str,
    new_password: str,
    callback: ErrorCallback | None = None,
) -> None

Set a new password with a password reset code.

Parameters:

Name Type Description Default
code str

the oobCode of the reset link.

required
new_password str

the new password.

required
callback ErrorCallback | None

gets None or the error.

None

check_action_code

check_action_code(
    code: str,
    callback: Callable[
        [ActionCodeInfo | None, AuthError | None], None
    ],
) -> None

Find out what an email action code is for, without using it.

Parameters:

Name Type Description Default
code str

the oobCode of the link.

required
callback Callable[[ActionCodeInfo | None, AuthError | None], None]

gets (ActionCodeInfo, None), or (None, error).

required

apply_action_code

apply_action_code(
    code: str, callback: ErrorCallback | None = None
) -> None

Use an email action code: verify an email address, or recover / change one.

Parameters:

Name Type Description Default
code str

the oobCode of the link.

required
callback ErrorCallback | None

gets None or the error.

None

fetch_sign_in_methods

fetch_sign_in_methods(
    email: str,
    callback: Callable[
        [list[str] | None, AuthError | None], None
    ],
) -> None

The sign-in methods used with email.

Deprecated by Firebase: with email enumeration protection on (the default), the list is always empty.

Parameters:

Name Type Description Default
email str

the email address.

required
callback Callable[[list[str] | None, AuthError | None], None]

gets (methods, None), for example ["password"], or (None, error).

required

revoke_token

revoke_token(
    authorization_code: str,
    callback: ErrorCallback | None = None,
) -> None

Revoke a Sign in with Apple token, before deleting an Apple user (App Store rule).

Parameters:

Name Type Description Default
authorization_code str

the authorizationCode Apple gave on a recent sign-in.

required
callback ErrorCallback | None

gets None or the error.

None

add_state_did_change_listener

add_state_did_change_listener(
    listener: UserListener,
) -> AuthStateListener

Listen to sign-in and sign-out.

listener runs now with the current user (or None), then each time a user signs in or out.

Parameters:

Name Type Description Default
listener UserListener

gets the User, or None when signed out.

required

Returns:

Type Description
AuthStateListener

An AuthStateListener. Call .remove() to stop.

add_id_token_did_change_listener

add_id_token_did_change_listener(
    listener: UserListener,
) -> AuthStateListener

Listen to sign-in, sign-out and ID token refreshes (about once an hour), for example to keep your backend's copy of the token fresh.

Parameters:

Name Type Description Default
listener UserListener

gets the User, or None when signed out.

required

Returns:

Type Description
AuthStateListener

An AuthStateListener. Call .remove() to stop.

use_emulator

use_emulator(
    host: str = "127.0.0.1", port: int = 9099
) -> None

Send this app's Auth calls to the local Auth emulator.

Call it right after core.configure(), before any other Auth call. Use it only in development and test builds. It also turns app verification off, so phone sign-in works without APNs or reCAPTCHA.

Parameters:

Name Type Description Default
host str

the emulator's host. "127.0.0.1" works in the iOS Simulator; on a device, use the Mac's LAN address.

'127.0.0.1'
port int

the emulator's port (firebase emulators:start uses 9099).

9099

use_app_language

use_app_language() -> None

Set language_code to the app's current language.

use_user_access_group

use_user_access_group(
    access_group: str | None,
) -> AuthError | None

Share the signed-in user with other apps (and extensions) through a keychain access group.

Parameters:

Name Type Description Default
access_group str | None

the keychain group (with your team ID prefix), or None to stop sharing.

required

Returns:

Type Description
AuthError | None

None, or the error (for example a keychain error).

get_stored_user

get_stored_user(
    access_group: str | None,
) -> tuple[User | None, AuthError | None]

The user saved in a keychain access group, without switching to it (for example the user signed in to your other app).

Sign in as them with update_current_user.

Parameters:

Name Type Description Default
access_group str | None

the keychain access group (with your team ID prefix), or None for the app's own keychain.

required

Returns:

Type Description
User | None

(user, None), (None, None) if no user is saved there, or

AuthError | None

(None, error) (for example without the Keychain Sharing

tuple[User | None, AuthError | None]

capability).

can_handle_url

can_handle_url(url: str) -> bool

Give a URL the app was opened with to Firebase Auth (reCAPTCHA and OAuth redirects).

Parameters:

Name Type Description Default
url str

the URL.

required

Returns:

Type Description
bool

True if Firebase Auth handled it.

can_handle_notification

can_handle_notification(user_info: dict[str, Any]) -> bool

Give a remote notification to Firebase Auth (silent push for phone sign-in).

Parameters:

Name Type Description Default
user_info dict[str, Any]

the notification's userInfo.

required

Returns:

Type Description
bool

True if it was for Firebase Auth.

set_apns_token

set_apns_token(
    token: bytes, token_type: int = APNS_TOKEN_TYPE_UNKNOWN
) -> None

Give Firebase Auth the app's APNs device token (phone sign-in).

Parameters:

Name Type Description Default
token bytes

the device token from didRegisterForRemoteNotificationsWithDeviceToken.

required
token_type int

APNS_TOKEN_TYPE_UNKNOWN / SANDBOX / PRODUCTION.

APNS_TOKEN_TYPE_UNKNOWN

AuthStateListener

AuthStateListener(
    handle: ObjCObject,
    remove: Callable[[ObjCObject], None],
    release: Callable[[], None],
)

Given back by add_state_did_change_listener and add_id_token_did_change_listener. Call remove() to stop.

Parameters:

Name Type Description Default
handle ObjCObject

the native listener handle.

required
remove Callable[[ObjCObject], None]

removes the handle from Firebase.

required
release Callable[[], None]

releases the listener's callback block.

required

Methods:

Name Description
remove

Stop the updates. Safe to call more than once.

remove

remove() -> None

Stop the updates. Safe to call more than once.

AuthCredential

AuthCredential(native: ObjCObject)

A sign-in credential for one provider.

Make credentials with the provider classes (EmailAuthProvider, GoogleAuthProvider, ...); you do not create them yourself.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRAuthCredential.

required

Attributes:

Name Type Description
native ObjCObject

The FIRAuthCredential, for SDK calls this wrapper does not cover.

provider str

The provider ID, for example "password" or "google.com".

native property

native: ObjCObject

The FIRAuthCredential, for SDK calls this wrapper does not cover.

provider property

provider: str

The provider ID, for example "password" or "google.com".

EmailAuthProvider

Credentials for email and password, or email link, sign-in.

Methods:

Name Description
credential

A credential for an email address and password.

credential_with_link

A credential for an email address and a sign-in link sent to it.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of email sign-in (both password and link).

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'password'

The provider ID of email sign-in (both password and link).

credential staticmethod

credential(email: str, password: str) -> AuthCredential

A credential for an email address and password.

Parameters:

Name Type Description Default
email str

the email address.

required
password str

the password.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "password".

credential_with_link(
    email: str, link: str
) -> AuthCredential

A credential for an email address and a sign-in link sent to it.

Parameters:

Name Type Description Default
email str

the email address the link was sent to.

required
link str

the full sign-in link the user opened.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "password".

FacebookAuthProvider

Credentials from Facebook Login access tokens.

Methods:

Name Description
credential

A credential from a Facebook access token.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of Facebook sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'facebook.com'

The provider ID of Facebook sign-in.

credential staticmethod

credential(access_token: str) -> AuthCredential

A credential from a Facebook access token.

Parameters:

Name Type Description Default
access_token str

the access token Facebook Login gave.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "facebook.com".

GameCenterAuthProvider

Credentials for the Game Center player signed in on the device.

Methods:

Name Description
get_credential

A credential for the local Game Center player.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of Game Center sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'gc.apple.com'

The provider ID of Game Center sign-in.

get_credential staticmethod

get_credential(callback: CredentialCallback) -> None

A credential for the local Game Center player.

The player must already be signed in to Game Center (GKLocalPlayer).

Parameters:

Name Type Description Default
callback CredentialCallback

gets (credential, None), or (None, error) (LOCAL_PLAYER_NOT_AUTHENTICATED if nobody is signed in).

required

GitHubAuthProvider

Credentials from GitHub OAuth access tokens (for the web flow, use OAuthProvider("github.com")).

Methods:

Name Description
credential

A credential from a GitHub OAuth access token.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of GitHub sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'github.com'

The provider ID of GitHub sign-in.

credential staticmethod

credential(token: str) -> AuthCredential

A credential from a GitHub OAuth access token.

Parameters:

Name Type Description Default
token str

the GitHub access token.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "github.com".

GoogleAuthProvider

Credentials from Google Sign-In tokens. For the whole flow, see pyios_firebase.auth.google.

Methods:

Name Description
credential

A credential from the tokens Google Sign-In gives.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of Google sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'google.com'

The provider ID of Google sign-in.

credential staticmethod

credential(
    id_token: str, access_token: str
) -> AuthCredential

A credential from the tokens Google Sign-In gives.

Parameters:

Name Type Description Default
id_token str

the Google ID token (GIDGoogleUser.idToken.tokenString).

required
access_token str

the Google access token (GIDGoogleUser.accessToken.tokenString).

required

Returns:

Type Description
AuthCredential

An AuthCredential for "google.com".

OAuthCredential

OAuthCredential(native: ObjCObject)

Bases: AuthCredential

A credential from an OAuth provider (Apple, Microsoft, Yahoo, ...).

Parameters:

Name Type Description Default
native ObjCObject

the native FIROAuthCredential.

required

Attributes:

Name Type Description
id_token str | None

The OpenID Connect ID token, if the provider gave one.

access_token str | None

The OAuth access token, if the provider gave one.

secret str | None

The OAuth 1.0 token secret, if the provider gave one.

id_token property

id_token: str | None

The OpenID Connect ID token, if the provider gave one.

access_token property

access_token: str | None

The OAuth access token, if the provider gave one.

secret property

secret: str | None

The OAuth 1.0 token secret, if the provider gave one.

OAuthProvider

OAuthProvider(
    provider_id: str,
    scopes: Sequence[str] | None = None,
    custom_parameters: Mapping[str, str] | None = None,
    auth: Auth | None = None,
)

A generic OAuth provider: Apple, Microsoft, Yahoo, GitHub, or any OIDC / SAML provider set up in the Firebase console.

As an object, it runs the provider's web sign-in flow (Auth.sign_in_with_provider, get_credential). The static methods make credentials from tokens you already have.

::

microsoft = OAuthProvider("microsoft.com", scopes=["mail.read"])
Auth.auth().sign_in_with_provider(microsoft, on_signed_in)

Parameters:

Name Type Description Default
provider_id str

the provider ID, for example "microsoft.com", "yahoo.com", "github.com", "oidc.my-provider". Not "facebook.com" or "apple.com" (except on the emulator): those need their own SDKs.

required
scopes Sequence[str] | None

OAuth scopes to ask for, beyond the provider's defaults.

None
custom_parameters Mapping[str, str] | None

extra OAuth parameters, for example {"prompt": "consent"} or {"tenant": "my-tenant-id"}.

None
auth Auth | None

the Auth instance to use (default: Auth.auth()).

None

Raises:

Type Description
ValueError

provider_id is "facebook.com" or "apple.com" outside the emulator (the SDK would stop the app).

Methods:

Name Description
get_credential

Run the provider's web sign-in flow and give back the credential,

credential

A credential from tokens you already have.

apple_credential

A Sign in with Apple credential. For the whole flow, see

Attributes:

Name Type Description
APPLE_PROVIDER_ID Final

The provider ID of Sign in with Apple.

scopes list[str]

The OAuth scopes asked for (beyond the provider's defaults).

custom_parameters dict[str, str]

Extra OAuth parameters sent to the provider.

native ObjCObject

The FIROAuthProvider.

provider_id str

The provider ID.

APPLE_PROVIDER_ID class-attribute instance-attribute

APPLE_PROVIDER_ID: Final = 'apple.com'

The provider ID of Sign in with Apple.

scopes property writable

scopes: list[str]

The OAuth scopes asked for (beyond the provider's defaults).

custom_parameters property writable

custom_parameters: dict[str, str]

Extra OAuth parameters sent to the provider.

native property

native: ObjCObject

The FIROAuthProvider.

provider_id property

provider_id: str

The provider ID.

get_credential

get_credential(callback: CredentialCallback) -> None

Run the provider's web sign-in flow and give back the credential, without signing in (for example to link it to the current user).

Shows the provider's page in an in-app browser. The app's Info.plist needs the URL scheme Firebase documents for the provider.

Parameters:

Name Type Description Default
callback CredentialCallback

gets (credential, None), or (None, error). error.cancelled is True when the user closed the browser. If the callback URL scheme is missing from Info.plist, the error says which one to add (the SDK itself would stop the app).

required

credential staticmethod

credential(
    provider_id: str,
    id_token: str | None = None,
    access_token: str | None = None,
    raw_nonce: str | None = None,
) -> OAuthCredential

A credential from tokens you already have.

Parameters:

Name Type Description Default
provider_id str

the provider ID, for example "microsoft.com".

required
id_token str | None

the OpenID Connect ID token, if any.

None
access_token str | None

the OAuth access token, if any.

None
raw_nonce str | None

the raw (unhashed) nonce the ID token was made for, if any.

None

Returns:

Type Description
OAuthCredential

An OAuthCredential.

Raises:

Type Description
ValueError

neither id_token nor access_token is given, or raw_nonce is given without id_token.

apple_credential staticmethod

apple_credential(
    id_token: str,
    raw_nonce: str | None,
    given_name: str | None = None,
    family_name: str | None = None,
) -> OAuthCredential

A Sign in with Apple credential. For the whole flow, see pyios_firebase.auth.apple.

Parameters:

Name Type Description Default
id_token str

the identity token Apple gave (as a string).

required
raw_nonce str | None

the raw nonce whose SHA-256 was sent to Apple, or None.

required
given_name str | None

the user's given name, which Apple shares only on the first sign-in. Passing it saves it in Firebase.

None
family_name str | None

the user's family name (same as given_name).

None

Returns:

Type Description
OAuthCredential

An OAuthCredential for "apple.com".

PhoneAuthProvider

PhoneAuthProvider(auth: Auth | None = None)

Phone number sign-in: send a code by SMS, then make a credential from it.

::

phone = PhoneAuthProvider()
phone.verify_phone_number("+15555550100", on_code_sent)
# later, with the code the user typed:
credential = phone.credential(verification_id, "123456")

Real phone sign-in needs push notifications (APNs) or reCAPTCHA set up; see Firebase's phone auth guide. With Auth.use_emulator it works without them. Either way, the app's Info.plist needs the callback URL scheme: the reversed client ID, or app- + the GOOGLE_APP_ID with - for :.

Parameters:

Name Type Description Default
auth Auth | None

the Auth instance to use (default: Auth.auth()).

None

Methods:

Name Description
verify_phone_number

Send a verification code to phone_number by SMS.

verify_phone_number_for_sign_in

Send the SMS code of an enrolled second factor, to finish a sign-in.

credential

A credential from the code the user received.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of phone sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'phone'

The provider ID of phone sign-in.

verify_phone_number

verify_phone_number(
    phone_number: str,
    callback: Callable[
        [str | None, AuthError | None], None
    ],
    multi_factor_session: MultiFactorSession | None = None,
) -> None

Send a verification code to phone_number by SMS.

Parameters:

Name Type Description Default
phone_number str

the number in E.164 format, for example "+15555550100".

required
callback Callable[[str | None, AuthError | None], None]

gets (verification_id, None), or (None, error). Keep verification_id for credential. If the callback URL scheme is missing from Info.plist, the error says which one to add (the SDK itself would stop the app).

required
multi_factor_session MultiFactorSession | None

to enroll the number as a second factor: the session from MultiFactor.get_session. None for sign-in with the number.

None

verify_phone_number_for_sign_in

verify_phone_number_for_sign_in(
    hint: PhoneMultiFactorInfo,
    session: MultiFactorSession,
    callback: Callable[
        [str | None, AuthError | None], None
    ],
) -> None

Send the SMS code of an enrolled second factor, to finish a sign-in.

Parameters:

Name Type Description Default
hint PhoneMultiFactorInfo

the phone factor chosen from MultiFactorResolver.hints.

required
session MultiFactorSession

MultiFactorResolver.session.

required
callback Callable[[str | None, AuthError | None], None]

gets (verification_id, None), or (None, error).

required

credential

credential(
    verification_id: str, verification_code: str
) -> AuthCredential

A credential from the code the user received.

Parameters:

Name Type Description Default
verification_id str

what verify_phone_number gave.

required
verification_code str

the code from the SMS.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "phone".

TwitterAuthProvider

Credentials from Twitter (X) OAuth 1.0 tokens.

Methods:

Name Description
credential

A credential from a Twitter OAuth token and secret.

Attributes:

Name Type Description
PROVIDER_ID Final

The provider ID of Twitter sign-in.

PROVIDER_ID class-attribute instance-attribute

PROVIDER_ID: Final = 'twitter.com'

The provider ID of Twitter sign-in.

credential staticmethod

credential(token: str, secret: str) -> AuthCredential

A credential from a Twitter OAuth token and secret.

Parameters:

Name Type Description Default
token str

the OAuth token.

required
secret str

the OAuth token secret.

required

Returns:

Type Description
AuthCredential

An AuthCredential for "twitter.com".

AuthError

Bases: FirebaseError

An error from Firebase Authentication (or from a sign-in sheet).

Attributes:

Name Type Description
name str

The AuthErrorCode name of code (for example "WRONG_PASSWORD"),

email str | None

The email address the error is about, when Firebase gives one (for

updated_credential AuthCredential | None

With ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL and

resolver MultiFactorResolver | None

With SECOND_FACTOR_REQUIRED: finishes the sign-in with a second

cancelled bool

True when the user closed a sign-in sheet (Google, Apple, web

message str

A sentence to show to the user, when the library has a better one than

name instance-attribute

name: str

The AuthErrorCode name of code (for example "WRONG_PASSWORD"), or "" for errors from other domains.

email instance-attribute

email: str | None

The email address the error is about, when Firebase gives one (for example with ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL).

updated_credential instance-attribute

updated_credential: AuthCredential | None

With ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL and CREDENTIAL_ALREADY_IN_USE: a credential to sign in with instead.

resolver instance-attribute

resolver: MultiFactorResolver | None

With SECOND_FACTOR_REQUIRED: finishes the sign-in with a second factor (see pyios_firebase.auth.multi_factor).

cancelled instance-attribute

cancelled: bool

True when the user closed a sign-in sheet (Google, Apple, web providers): not a failure to report.

message instance-attribute

message: str

A sentence to show to the user, when the library has a better one than description (Apple sign-in); otherwise "".

AuthErrorCode

The error.code values of Firebase Authentication errors.

Generated from FIRAuthErrorCode in the Firebase iOS SDK (13.1.1). The numbers are fixed in the SDK; check them when you update it.

Attributes:

Name Type Description
INVALID_CUSTOM_TOKEN Final

Indicates a validation error with the custom token.

CUSTOM_TOKEN_MISMATCH Final

Indicates the service account and the API key belong to different projects.

INVALID_CREDENTIAL Final

Indicates the IDP token or requestUri is invalid.

USER_DISABLED Final

Indicates the user's account is disabled on the server.

OPERATION_NOT_ALLOWED Final

Indicates the administrator disabled sign in with the specified identity provider.

EMAIL_ALREADY_IN_USE Final

Indicates the email used to attempt a sign up is already in use.

INVALID_EMAIL Final

Indicates the email is invalid.

WRONG_PASSWORD Final

Indicates the user attempted sign in with a wrong password.

TOO_MANY_REQUESTS Final

Indicates that too many requests were made to a server method.

USER_NOT_FOUND Final

Indicates the user account was not found.

ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL Final

Indicates account linking is required.

REQUIRES_RECENT_LOGIN Final

Indicates the user has attempted to change email or password more than 5 minutes after signing in.

PROVIDER_ALREADY_LINKED Final

Indicates an attempt to link a provider to which the account is already linked.

NO_SUCH_PROVIDER Final

Indicates an attempt to unlink a provider that is not linked.

INVALID_USER_TOKEN Final

Indicates user's saved auth credential is invalid the user needs to sign in again.

NETWORK_ERROR Final

Indicates a network error occurred (such as a timeout interrupted connection or unreachable host).

USER_TOKEN_EXPIRED Final

Indicates the saved token has expired for example the user may have changed account password on another device.

INVALID_API_KEY Final

Indicates an invalid API key was supplied in the request.

USER_MISMATCH Final

Indicates that an attempt was made to reauthenticate with a user which is not the current user.

CREDENTIAL_ALREADY_IN_USE Final

Indicates an attempt to link with a credential that has already been linked with a different Firebase account.

WEAK_PASSWORD Final

Indicates an attempt to set a password that is considered too weak.

APP_NOT_AUTHORIZED Final

Indicates the App is not authorized to use Firebase Authentication with the provided API Key.

EXPIRED_ACTION_CODE Final

Indicates the OOB code is expired.

INVALID_ACTION_CODE Final

Indicates the OOB code is invalid.

INVALID_MESSAGE_PAYLOAD Final

Indicates that there are invalid parameters in the payload during a 'send password reset email' attempt.

INVALID_SENDER Final

Indicates that the sender email is invalid during a 'send password reset email' attempt.

INVALID_RECIPIENT_EMAIL Final

Indicates that the recipient email is invalid.

MISSING_EMAIL Final

Indicates that an email address was expected but one was not provided.

MISSING_IOS_BUNDLE_ID Final

Indicates that the iOS bundle ID is missing when a iOS App Store ID is provided.

MISSING_ANDROID_PACKAGE_NAME Final

Indicates that the android package name is missing when the androidInstallApp flag is set to true.

UNAUTHORIZED_DOMAIN Final

Indicates that the domain specified in the continue URL is not allowlisted in the Firebase console.

INVALID_CONTINUE_URI Final

Indicates that the domain specified in the continue URI is not valid.

MISSING_CONTINUE_URI Final

Indicates that a continue URI was not provided in a request to the backend which requires one.

MISSING_PHONE_NUMBER Final

Indicates that a phone number was not provided in a call to verifyPhoneNumber:completion:.

INVALID_PHONE_NUMBER Final

Indicates that an invalid phone number was provided in a call to verifyPhoneNumber:completion:.

MISSING_VERIFICATION_CODE Final

Indicates that the phone auth credential was created with an empty verification code.

INVALID_VERIFICATION_CODE Final

Indicates that an invalid verification code was used in the verifyPhoneNumber request.

MISSING_VERIFICATION_ID Final

Indicates that the phone auth credential was created with an empty verification ID.

INVALID_VERIFICATION_ID Final

Indicates that an invalid verification ID was used in the verifyPhoneNumber request.

MISSING_APP_CREDENTIAL Final

Indicates that the APNS device token is missing in the verifyClient request.

INVALID_APP_CREDENTIAL Final

Indicates that an invalid APNS device token was used in the verifyClient request.

SESSION_EXPIRED Final

Indicates that the SMS code has expired.

QUOTA_EXCEEDED Final

Indicates that the quota of SMS messages for a given project has been exceeded.

MISSING_APP_TOKEN Final

Indicates that the APNs device token could not be obtained.

NOTIFICATION_NOT_FORWARDED Final

Indicates that the app fails to forward remote notification to FIRAuth.

APP_NOT_VERIFIED Final

Indicates that the app could not be verified by Firebase during phone number authentication.

CAPTCHA_CHECK_FAILED Final

Indicates that the reCAPTCHA token is not valid.

WEB_CONTEXT_ALREADY_PRESENTED Final

Indicates that an attempt was made to present a new web context while one was already being presented.

WEB_CONTEXT_CANCELLED Final

Indicates that the URL presentation was cancelled prematurely by the user.

APP_VERIFICATION_USER_INTERACTION_FAILURE Final

Indicates a general failure during the app verification flow.

INVALID_CLIENT_ID Final

Indicates that the clientID used to invoke a web flow is invalid.

WEB_NETWORK_REQUEST_FAILED Final

Indicates that a network request within a SFSafariViewController or WKWebView failed.

WEB_INTERNAL_ERROR Final

Indicates that an internal error occurred within a SFSafariViewController or WKWebView.

WEB_SIGN_IN_USER_INTERACTION_FAILURE Final

Indicates a general failure during a web sign-in flow.

LOCAL_PLAYER_NOT_AUTHENTICATED Final

Indicates that the local player was not authenticated prior to attempting Game Center signin.

NULL_USER Final

Indicates that a non-null user was expected as an argument to the operation but a null user was provided.

INVALID_PROVIDER_ID Final

Represents the error code for when the given provider id for a web operation is invalid.

TENANT_ID_MISMATCH Final

Represents the error code for when an attempt is made to update the current user with a tenantId that differs from the current FirebaseAuth instance's tenantId.

UNSUPPORTED_TENANT_OPERATION Final

Represents the error code for when a request is made to the backend with an associated tenant ID for an operation that does not support multi-tenancy.

INVALID_HOSTING_LINK_DOMAIN Final

Indicates that the provided Firebase Hosting Link domain is not owned by the current project.

REJECTED_CREDENTIAL Final

Indicates that the credential is rejected because it's malformed or mismatching.

GAME_KIT_NOT_LINKED Final

Indicates that the GameKit framework is not linked prior to attempting Game Center signin.

SECOND_FACTOR_REQUIRED Final

Indicates that the second factor is required for signin.

MISSING_MULTI_FACTOR_SESSION Final

Indicates that the multi factor session is missing.

MISSING_MULTI_FACTOR_INFO Final

Indicates that the multi factor info is missing.

INVALID_MULTI_FACTOR_SESSION Final

Indicates that the multi factor session is invalid.

MULTI_FACTOR_INFO_NOT_FOUND Final

Indicates that the multi factor info is not found.

ADMIN_RESTRICTED_OPERATION Final

Indicates that the operation is admin restricted.

UNVERIFIED_EMAIL Final

Indicates that the email is required for verification.

SECOND_FACTOR_ALREADY_ENROLLED Final

Indicates that the second factor is already enrolled.

MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED Final

Indicates that the maximum second factor count is exceeded.

UNSUPPORTED_FIRST_FACTOR Final

Indicates that the first factor is not supported.

EMAIL_CHANGE_NEEDS_VERIFICATION Final

Indicates that the a verified email is required to changed to.

MISSING_CLIENT_IDENTIFIER Final

Indicates that the request does not contain a client identifier.

MISSING_OR_INVALID_NONCE Final

Indicates that the nonce is missing or invalid.

BLOCKING_CLOUD_FUNCTION_ERROR Final

Raised when a Cloud Function returns a blocking error.

RECAPTCHA_NOT_ENABLED Final

Indicates that reCAPTCHA Enterprise integration is not enabled for this project.

MISSING_RECAPTCHA_TOKEN Final

Indicates that the reCAPTCHA token is missing from the backend request.

INVALID_RECAPTCHA_TOKEN Final

Indicates that the reCAPTCHA token sent with the backend request is invalid.

INVALID_RECAPTCHA_ACTION Final

Indicates that the requested reCAPTCHA action is invalid.

MISSING_CLIENT_TYPE Final

Indicates that the client type is missing from the request.

MISSING_RECAPTCHA_VERSION Final

Indicates that the reCAPTCHA version is missing from the request.

INVALID_RECAPTCHA_VERSION Final

Indicates that the reCAPTCHA version sent to the backend is invalid.

INVALID_REQ_TYPE Final

Indicates that the request type sent to the backend is invalid.

RECAPTCHA_SDK_NOT_LINKED Final

Indicates that the reCAPTCHA SDK is not linked to the app.

RECAPTCHA_SITE_KEY_MISSING Final

Indicates that the reCAPTCHA SDK site key wasn't found.

RECAPTCHA_ACTION_CREATION_FAILED Final

Indicates that the reCAPTCHA SDK actions class failed to create.

PASSWORD_DOES_NOT_MEET_REQUIREMENTS Final

Indicates that the password does not meet the project's password policy.

KEYCHAIN_ERROR Final

Indicates an error occurred while attempting to access the keychain.

INTERNAL_ERROR Final

Indicates an internal error occurred.

MALFORMED_JWT Final

Raised when a JWT fails to parse correctly.

INVALID_CUSTOM_TOKEN class-attribute instance-attribute

INVALID_CUSTOM_TOKEN: Final = 17000

Indicates a validation error with the custom token.

CUSTOM_TOKEN_MISMATCH class-attribute instance-attribute

CUSTOM_TOKEN_MISMATCH: Final = 17002

Indicates the service account and the API key belong to different projects.

INVALID_CREDENTIAL class-attribute instance-attribute

INVALID_CREDENTIAL: Final = 17004

Indicates the IDP token or requestUri is invalid.

USER_DISABLED class-attribute instance-attribute

USER_DISABLED: Final = 17005

Indicates the user's account is disabled on the server.

OPERATION_NOT_ALLOWED class-attribute instance-attribute

OPERATION_NOT_ALLOWED: Final = 17006

Indicates the administrator disabled sign in with the specified identity provider.

EMAIL_ALREADY_IN_USE class-attribute instance-attribute

EMAIL_ALREADY_IN_USE: Final = 17007

Indicates the email used to attempt a sign up is already in use.

INVALID_EMAIL class-attribute instance-attribute

INVALID_EMAIL: Final = 17008

Indicates the email is invalid.

WRONG_PASSWORD class-attribute instance-attribute

WRONG_PASSWORD: Final = 17009

Indicates the user attempted sign in with a wrong password.

TOO_MANY_REQUESTS class-attribute instance-attribute

TOO_MANY_REQUESTS: Final = 17010

Indicates that too many requests were made to a server method.

USER_NOT_FOUND class-attribute instance-attribute

USER_NOT_FOUND: Final = 17011

Indicates the user account was not found.

ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL class-attribute instance-attribute

ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL: Final = 17012

Indicates account linking is required.

REQUIRES_RECENT_LOGIN class-attribute instance-attribute

REQUIRES_RECENT_LOGIN: Final = 17014

Indicates the user has attempted to change email or password more than 5 minutes after signing in.

PROVIDER_ALREADY_LINKED class-attribute instance-attribute

PROVIDER_ALREADY_LINKED: Final = 17015

Indicates an attempt to link a provider to which the account is already linked.

NO_SUCH_PROVIDER class-attribute instance-attribute

NO_SUCH_PROVIDER: Final = 17016

Indicates an attempt to unlink a provider that is not linked.

INVALID_USER_TOKEN class-attribute instance-attribute

INVALID_USER_TOKEN: Final = 17017

Indicates user's saved auth credential is invalid the user needs to sign in again.

NETWORK_ERROR class-attribute instance-attribute

NETWORK_ERROR: Final = 17020

Indicates a network error occurred (such as a timeout interrupted connection or unreachable host).

USER_TOKEN_EXPIRED class-attribute instance-attribute

USER_TOKEN_EXPIRED: Final = 17021

Indicates the saved token has expired for example the user may have changed account password on another device.

INVALID_API_KEY class-attribute instance-attribute

INVALID_API_KEY: Final = 17023

Indicates an invalid API key was supplied in the request.

USER_MISMATCH class-attribute instance-attribute

USER_MISMATCH: Final = 17024

Indicates that an attempt was made to reauthenticate with a user which is not the current user.

CREDENTIAL_ALREADY_IN_USE class-attribute instance-attribute

CREDENTIAL_ALREADY_IN_USE: Final = 17025

Indicates an attempt to link with a credential that has already been linked with a different Firebase account.

WEAK_PASSWORD class-attribute instance-attribute

WEAK_PASSWORD: Final = 17026

Indicates an attempt to set a password that is considered too weak.

APP_NOT_AUTHORIZED class-attribute instance-attribute

APP_NOT_AUTHORIZED: Final = 17028

Indicates the App is not authorized to use Firebase Authentication with the provided API Key.

EXPIRED_ACTION_CODE class-attribute instance-attribute

EXPIRED_ACTION_CODE: Final = 17029

Indicates the OOB code is expired.

INVALID_ACTION_CODE class-attribute instance-attribute

INVALID_ACTION_CODE: Final = 17030

Indicates the OOB code is invalid.

INVALID_MESSAGE_PAYLOAD class-attribute instance-attribute

INVALID_MESSAGE_PAYLOAD: Final = 17031

Indicates that there are invalid parameters in the payload during a 'send password reset email' attempt.

INVALID_SENDER class-attribute instance-attribute

INVALID_SENDER: Final = 17032

Indicates that the sender email is invalid during a 'send password reset email' attempt.

INVALID_RECIPIENT_EMAIL class-attribute instance-attribute

INVALID_RECIPIENT_EMAIL: Final = 17033

Indicates that the recipient email is invalid.

MISSING_EMAIL class-attribute instance-attribute

MISSING_EMAIL: Final = 17034

Indicates that an email address was expected but one was not provided.

MISSING_IOS_BUNDLE_ID class-attribute instance-attribute

MISSING_IOS_BUNDLE_ID: Final = 17036

Indicates that the iOS bundle ID is missing when a iOS App Store ID is provided.

MISSING_ANDROID_PACKAGE_NAME class-attribute instance-attribute

MISSING_ANDROID_PACKAGE_NAME: Final = 17037

Indicates that the android package name is missing when the androidInstallApp flag is set to true.

UNAUTHORIZED_DOMAIN class-attribute instance-attribute

UNAUTHORIZED_DOMAIN: Final = 17038

Indicates that the domain specified in the continue URL is not allowlisted in the Firebase console.

INVALID_CONTINUE_URI class-attribute instance-attribute

INVALID_CONTINUE_URI: Final = 17039

Indicates that the domain specified in the continue URI is not valid.

MISSING_CONTINUE_URI class-attribute instance-attribute

MISSING_CONTINUE_URI: Final = 17040

Indicates that a continue URI was not provided in a request to the backend which requires one.

MISSING_PHONE_NUMBER class-attribute instance-attribute

MISSING_PHONE_NUMBER: Final = 17041

Indicates that a phone number was not provided in a call to verifyPhoneNumber:completion:.

INVALID_PHONE_NUMBER class-attribute instance-attribute

INVALID_PHONE_NUMBER: Final = 17042

Indicates that an invalid phone number was provided in a call to verifyPhoneNumber:completion:.

MISSING_VERIFICATION_CODE class-attribute instance-attribute

MISSING_VERIFICATION_CODE: Final = 17043

Indicates that the phone auth credential was created with an empty verification code.

INVALID_VERIFICATION_CODE class-attribute instance-attribute

INVALID_VERIFICATION_CODE: Final = 17044

Indicates that an invalid verification code was used in the verifyPhoneNumber request.

MISSING_VERIFICATION_ID class-attribute instance-attribute

MISSING_VERIFICATION_ID: Final = 17045

Indicates that the phone auth credential was created with an empty verification ID.

INVALID_VERIFICATION_ID class-attribute instance-attribute

INVALID_VERIFICATION_ID: Final = 17046

Indicates that an invalid verification ID was used in the verifyPhoneNumber request.

MISSING_APP_CREDENTIAL class-attribute instance-attribute

MISSING_APP_CREDENTIAL: Final = 17047

Indicates that the APNS device token is missing in the verifyClient request.

INVALID_APP_CREDENTIAL class-attribute instance-attribute

INVALID_APP_CREDENTIAL: Final = 17048

Indicates that an invalid APNS device token was used in the verifyClient request.

SESSION_EXPIRED class-attribute instance-attribute

SESSION_EXPIRED: Final = 17051

Indicates that the SMS code has expired.

QUOTA_EXCEEDED class-attribute instance-attribute

QUOTA_EXCEEDED: Final = 17052

Indicates that the quota of SMS messages for a given project has been exceeded.

MISSING_APP_TOKEN class-attribute instance-attribute

MISSING_APP_TOKEN: Final = 17053

Indicates that the APNs device token could not be obtained.

NOTIFICATION_NOT_FORWARDED class-attribute instance-attribute

NOTIFICATION_NOT_FORWARDED: Final = 17054

Indicates that the app fails to forward remote notification to FIRAuth.

APP_NOT_VERIFIED class-attribute instance-attribute

APP_NOT_VERIFIED: Final = 17055

Indicates that the app could not be verified by Firebase during phone number authentication.

CAPTCHA_CHECK_FAILED class-attribute instance-attribute

CAPTCHA_CHECK_FAILED: Final = 17056

Indicates that the reCAPTCHA token is not valid.

WEB_CONTEXT_ALREADY_PRESENTED class-attribute instance-attribute

WEB_CONTEXT_ALREADY_PRESENTED: Final = 17057

Indicates that an attempt was made to present a new web context while one was already being presented.

WEB_CONTEXT_CANCELLED class-attribute instance-attribute

WEB_CONTEXT_CANCELLED: Final = 17058

Indicates that the URL presentation was cancelled prematurely by the user.

APP_VERIFICATION_USER_INTERACTION_FAILURE class-attribute instance-attribute

APP_VERIFICATION_USER_INTERACTION_FAILURE: Final = 17059

Indicates a general failure during the app verification flow.

INVALID_CLIENT_ID class-attribute instance-attribute

INVALID_CLIENT_ID: Final = 17060

Indicates that the clientID used to invoke a web flow is invalid.

WEB_NETWORK_REQUEST_FAILED class-attribute instance-attribute

WEB_NETWORK_REQUEST_FAILED: Final = 17061

Indicates that a network request within a SFSafariViewController or WKWebView failed.

WEB_INTERNAL_ERROR class-attribute instance-attribute

WEB_INTERNAL_ERROR: Final = 17062

Indicates that an internal error occurred within a SFSafariViewController or WKWebView.

WEB_SIGN_IN_USER_INTERACTION_FAILURE class-attribute instance-attribute

WEB_SIGN_IN_USER_INTERACTION_FAILURE: Final = 17063

Indicates a general failure during a web sign-in flow.

LOCAL_PLAYER_NOT_AUTHENTICATED class-attribute instance-attribute

LOCAL_PLAYER_NOT_AUTHENTICATED: Final = 17066

Indicates that the local player was not authenticated prior to attempting Game Center signin.

NULL_USER class-attribute instance-attribute

NULL_USER: Final = 17067

Indicates that a non-null user was expected as an argument to the operation but a null user was provided.

INVALID_PROVIDER_ID class-attribute instance-attribute

INVALID_PROVIDER_ID: Final = 17071

Represents the error code for when the given provider id for a web operation is invalid.

TENANT_ID_MISMATCH class-attribute instance-attribute

TENANT_ID_MISMATCH: Final = 17072

Represents the error code for when an attempt is made to update the current user with a tenantId that differs from the current FirebaseAuth instance's tenantId.

UNSUPPORTED_TENANT_OPERATION class-attribute instance-attribute

UNSUPPORTED_TENANT_OPERATION: Final = 17073

Represents the error code for when a request is made to the backend with an associated tenant ID for an operation that does not support multi-tenancy.

INVALID_HOSTING_LINK_DOMAIN: Final = 17214

Indicates that the provided Firebase Hosting Link domain is not owned by the current project.

REJECTED_CREDENTIAL class-attribute instance-attribute

REJECTED_CREDENTIAL: Final = 17075

Indicates that the credential is rejected because it's malformed or mismatching.

GAME_KIT_NOT_LINKED class-attribute instance-attribute

GAME_KIT_NOT_LINKED: Final = 17076

Indicates that the GameKit framework is not linked prior to attempting Game Center signin.

SECOND_FACTOR_REQUIRED class-attribute instance-attribute

SECOND_FACTOR_REQUIRED: Final = 17078

Indicates that the second factor is required for signin.

MISSING_MULTI_FACTOR_SESSION class-attribute instance-attribute

MISSING_MULTI_FACTOR_SESSION: Final = 17081

Indicates that the multi factor session is missing.

MISSING_MULTI_FACTOR_INFO class-attribute instance-attribute

MISSING_MULTI_FACTOR_INFO: Final = 17082

Indicates that the multi factor info is missing.

INVALID_MULTI_FACTOR_SESSION class-attribute instance-attribute

INVALID_MULTI_FACTOR_SESSION: Final = 17083

Indicates that the multi factor session is invalid.

MULTI_FACTOR_INFO_NOT_FOUND class-attribute instance-attribute

MULTI_FACTOR_INFO_NOT_FOUND: Final = 17084

Indicates that the multi factor info is not found.

ADMIN_RESTRICTED_OPERATION class-attribute instance-attribute

ADMIN_RESTRICTED_OPERATION: Final = 17085

Indicates that the operation is admin restricted.

UNVERIFIED_EMAIL class-attribute instance-attribute

UNVERIFIED_EMAIL: Final = 17086

Indicates that the email is required for verification.

SECOND_FACTOR_ALREADY_ENROLLED class-attribute instance-attribute

SECOND_FACTOR_ALREADY_ENROLLED: Final = 17087

Indicates that the second factor is already enrolled.

MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED class-attribute instance-attribute

MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED: Final = 17088

Indicates that the maximum second factor count is exceeded.

UNSUPPORTED_FIRST_FACTOR class-attribute instance-attribute

UNSUPPORTED_FIRST_FACTOR: Final = 17089

Indicates that the first factor is not supported.

EMAIL_CHANGE_NEEDS_VERIFICATION class-attribute instance-attribute

EMAIL_CHANGE_NEEDS_VERIFICATION: Final = 17090

Indicates that the a verified email is required to changed to.

MISSING_CLIENT_IDENTIFIER class-attribute instance-attribute

MISSING_CLIENT_IDENTIFIER: Final = 17093

Indicates that the request does not contain a client identifier.

MISSING_OR_INVALID_NONCE class-attribute instance-attribute

MISSING_OR_INVALID_NONCE: Final = 17094

Indicates that the nonce is missing or invalid.

BLOCKING_CLOUD_FUNCTION_ERROR class-attribute instance-attribute

BLOCKING_CLOUD_FUNCTION_ERROR: Final = 17105

Raised when a Cloud Function returns a blocking error.

RECAPTCHA_NOT_ENABLED class-attribute instance-attribute

RECAPTCHA_NOT_ENABLED: Final = 17200

Indicates that reCAPTCHA Enterprise integration is not enabled for this project.

MISSING_RECAPTCHA_TOKEN class-attribute instance-attribute

MISSING_RECAPTCHA_TOKEN: Final = 17201

Indicates that the reCAPTCHA token is missing from the backend request.

INVALID_RECAPTCHA_TOKEN class-attribute instance-attribute

INVALID_RECAPTCHA_TOKEN: Final = 17202

Indicates that the reCAPTCHA token sent with the backend request is invalid.

INVALID_RECAPTCHA_ACTION class-attribute instance-attribute

INVALID_RECAPTCHA_ACTION: Final = 17203

Indicates that the requested reCAPTCHA action is invalid.

MISSING_CLIENT_TYPE class-attribute instance-attribute

MISSING_CLIENT_TYPE: Final = 17204

Indicates that the client type is missing from the request.

MISSING_RECAPTCHA_VERSION class-attribute instance-attribute

MISSING_RECAPTCHA_VERSION: Final = 17205

Indicates that the reCAPTCHA version is missing from the request.

INVALID_RECAPTCHA_VERSION class-attribute instance-attribute

INVALID_RECAPTCHA_VERSION: Final = 17206

Indicates that the reCAPTCHA version sent to the backend is invalid.

INVALID_REQ_TYPE class-attribute instance-attribute

INVALID_REQ_TYPE: Final = 17207

Indicates that the request type sent to the backend is invalid.

RECAPTCHA_SDK_NOT_LINKED class-attribute instance-attribute

RECAPTCHA_SDK_NOT_LINKED: Final = 17208

Indicates that the reCAPTCHA SDK is not linked to the app.

RECAPTCHA_SITE_KEY_MISSING class-attribute instance-attribute

RECAPTCHA_SITE_KEY_MISSING: Final = 17209

Indicates that the reCAPTCHA SDK site key wasn't found.

RECAPTCHA_ACTION_CREATION_FAILED class-attribute instance-attribute

RECAPTCHA_ACTION_CREATION_FAILED: Final = 17210

Indicates that the reCAPTCHA SDK actions class failed to create.

PASSWORD_DOES_NOT_MEET_REQUIREMENTS class-attribute instance-attribute

PASSWORD_DOES_NOT_MEET_REQUIREMENTS: Final = 17211

Indicates that the password does not meet the project's password policy.

KEYCHAIN_ERROR class-attribute instance-attribute

KEYCHAIN_ERROR: Final = 17995

Indicates an error occurred while attempting to access the keychain.

INTERNAL_ERROR class-attribute instance-attribute

INTERNAL_ERROR: Final = 17999

Indicates an internal error occurred.

MALFORMED_JWT class-attribute instance-attribute

MALFORMED_JWT: Final = 18000

Raised when a JWT fails to parse correctly.

MultiFactor

MultiFactor(native: ObjCObject)

A user's second factors. Get it with User.multi_factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactor.

required

Methods:

Name Description
get_session

Start an enrollment: get a session for SMS verification or a TOTP secret.

enroll

Enroll a second factor.

unenroll

Remove a second factor.

Attributes:

Name Type Description
enrolled_factors list[MultiFactorInfo]

The enrolled second factors (PhoneMultiFactorInfo for SMS).

enrolled_factors property

enrolled_factors: list[MultiFactorInfo]

The enrolled second factors (PhoneMultiFactorInfo for SMS).

get_session

get_session(
    callback: Callable[
        [MultiFactorSession | None, AuthError | None], None
    ],
) -> None

Start an enrollment: get a session for SMS verification or a TOTP secret.

Parameters:

Name Type Description Default
callback Callable[[MultiFactorSession | None, AuthError | None], None]

gets (MultiFactorSession, None), or (None, error) (REQUIRES_RECENT_LOGIN if the sign-in is old).

required

enroll

enroll(
    assertion: MultiFactorAssertion,
    display_name: str | None = None,
    callback: ErrorCallback | None = None,
) -> None

Enroll a second factor.

Parameters:

Name Type Description Default
assertion MultiFactorAssertion

from PhoneMultiFactorGenerator or TOTPMultiFactorGenerator.assertion_for_enrollment.

required
display_name str | None

a name to show in sign-in hints, for example "Work phone".

None
callback ErrorCallback | None

gets None or the error (UNVERIFIED_EMAIL if the email address is not verified yet).

None

unenroll

unenroll(
    factor: MultiFactorInfo | str,
    callback: ErrorCallback | None = None,
) -> None

Remove a second factor.

Parameters:

Name Type Description Default
factor MultiFactorInfo | str

the factor, or its uid.

required
callback ErrorCallback | None

gets None or the error. Removing the factor used to sign in signs the user out.

None

MultiFactorAssertion

MultiFactorAssertion(native: ObjCObject)

Proof of a second factor, for MultiFactor.enroll or MultiFactorResolver.resolve_sign_in. Make it with PhoneMultiFactorGenerator or TOTPMultiFactorGenerator.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorAssertion.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorAssertion.

factor_id str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

native property

native: ObjCObject

The FIRMultiFactorAssertion.

factor_id property

factor_id: str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

MultiFactorInfo

MultiFactorInfo(native: ObjCObject)

One enrolled second factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorInfo.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorInfo.

uid str

The factor's ID (its enrollment ID for TOTP sign-in).

factor_id str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

display_name str | None

The name given at enrollment, or None.

enrollment_date datetime | None

When the factor was enrolled (UTC).

native property

native: ObjCObject

The FIRMultiFactorInfo.

uid property

uid: str

The factor's ID (its enrollment ID for TOTP sign-in).

factor_id property

factor_id: str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

display_name property

display_name: str | None

The name given at enrollment, or None.

enrollment_date property

enrollment_date: datetime | None

When the factor was enrolled (UTC).

MultiFactorResolver

MultiFactorResolver(native: ObjCObject)

Finishes a sign-in that needs a second factor. Get it from AuthError.resolver when error.code == AuthErrorCode.SECOND_FACTOR_REQUIRED.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorResolver.

required

Methods:

Name Description
resolve_sign_in

Finish the sign-in with a second factor.

Attributes:

Name Type Description
hints list[MultiFactorInfo]

The user's enrolled factors: let them choose one.

session MultiFactorSession

The session proving the first factor: pass it to SMS verification.

hints property

hints: list[MultiFactorInfo]

The user's enrolled factors: let them choose one.

session property

The session proving the first factor: pass it to SMS verification.

resolve_sign_in

resolve_sign_in(
    assertion: MultiFactorAssertion,
    callback: Callable[
        [AuthDataResult | None, AuthError | None], None
    ]
    | None = None,
) -> None

Finish the sign-in with a second factor.

Parameters:

Name Type Description Default
assertion MultiFactorAssertion

from PhoneMultiFactorGenerator.assertion or TOTPMultiFactorGenerator.assertion_for_sign_in.

required
callback Callable[[AuthDataResult | None, AuthError | None], None] | None

gets (AuthDataResult, None), or (None, error) (INVALID_VERIFICATION_CODE for a wrong code).

None

MultiFactorSession

MultiFactorSession(native: ObjCObject)

Proves the first factor was just completed (or that the user is signed in, for enrollment). Pass it to SMS verification or generate_secret.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorSession.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorSession.

native property

native: ObjCObject

The FIRMultiFactorSession.

PhoneMultiFactorGenerator

Make SMS second-factor assertions.

Methods:

Name Description
assertion

An assertion from a phone credential.

assertion staticmethod

assertion(
    credential: AuthCredential,
) -> MultiFactorAssertion

An assertion from a phone credential.

Parameters:

Name Type Description Default
credential AuthCredential

from PhoneAuthProvider.credential after verify_phone_number (enrollment) or verify_phone_number_for_sign_in (sign-in).

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "phone".

PhoneMultiFactorInfo

PhoneMultiFactorInfo(native: ObjCObject)

Bases: MultiFactorInfo

An enrolled SMS second factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRPhoneMultiFactorInfo.

required

Attributes:

Name Type Description
phone_number str

The phone number, usually masked in sign-in hints (+*******0100).

phone_number property

phone_number: str

The phone number, usually masked in sign-in hints (+*******0100).

TOTPMultiFactorGenerator

Make TOTP (authenticator app) secrets and assertions.

Methods:

Name Description
generate_secret

Make a new TOTP secret for enrollment.

assertion_for_enrollment

An assertion to enroll the authenticator app.

assertion_for_sign_in

An assertion to finish a sign-in with the authenticator app.

generate_secret staticmethod

generate_secret(
    session: MultiFactorSession,
    callback: Callable[
        [TOTPSecret | None, AuthError | None], None
    ],
) -> None

Make a new TOTP secret for enrollment.

Parameters:

Name Type Description Default
session MultiFactorSession

from MultiFactor.get_session.

required
callback Callable[[TOTPSecret | None, AuthError | None], None]

gets (TOTPSecret, None), or (None, error).

required

assertion_for_enrollment staticmethod

assertion_for_enrollment(
    secret: TOTPSecret, one_time_password: str
) -> MultiFactorAssertion

An assertion to enroll the authenticator app.

Parameters:

Name Type Description Default
secret TOTPSecret

from generate_secret.

required
one_time_password str

the 6-digit code the app shows now.

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "totp".

assertion_for_sign_in staticmethod

assertion_for_sign_in(
    enrollment_id: str, one_time_password: str
) -> MultiFactorAssertion

An assertion to finish a sign-in with the authenticator app.

Parameters:

Name Type Description Default
enrollment_id str

the uid of the TOTP hint in MultiFactorResolver.hints.

required
one_time_password str

the 6-digit code the app shows now.

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "totp".

TOTPSecret

TOTPSecret(native: ObjCObject)

A new TOTP secret, to show to the user while they set up their authenticator app.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRTOTPSecret.

required

Methods:

Name Description
shared_secret_key

The secret, to type into an authenticator app by hand.

generate_qr_code_url

An otpauth:// URL, to show as a QR code for an authenticator app.

open_in_otp_app

Open the URL in an installed authenticator app (if there is one).

Attributes:

Name Type Description
native ObjCObject

The FIRTOTPSecret.

native property

native: ObjCObject

The FIRTOTPSecret.

shared_secret_key

shared_secret_key() -> str

The secret, to type into an authenticator app by hand.

generate_qr_code_url

generate_qr_code_url(account_name: str, issuer: str) -> str

An otpauth:// URL, to show as a QR code for an authenticator app.

Parameters:

Name Type Description Default
account_name str

shown in the authenticator app, usually the email.

required
issuer str

your app's name, shown in the authenticator app.

required

Returns:

Type Description
str

The URL.

open_in_otp_app

open_in_otp_app(qr_code_url: str) -> None

Open the URL in an installed authenticator app (if there is one).

Parameters:

Name Type Description Default
qr_code_url str

from generate_qr_code_url.

required

ActionCodeInfo dataclass

ActionCodeInfo(
    operation: int, email: str, previous_email: str | None
)

What Auth.check_action_code learned about an email action code.

Methods:

Name Description
from_native

Copy a native FIRActionCodeInfo.

Attributes:

Name Type Description
operation int

An ActionCodeOperation value.

email str

The email address the code is for.

previous_email str | None

For RECOVER_EMAIL / VERIFY_AND_CHANGE_EMAIL: the old address.

operation instance-attribute

operation: int

An ActionCodeOperation value.

Firebase iOS SDK 13.1.1 only recognises request types in camel case ("resetPassword"); a server that sends "PASSWORD_RESET", as the Auth emulator does, gives UNKNOWN. Do not rely on it alone.

email instance-attribute

email: str

The email address the code is for.

previous_email instance-attribute

previous_email: str | None

For RECOVER_EMAIL / VERIFY_AND_CHANGE_EMAIL: the old address.

from_native classmethod

from_native(native: ObjCObject) -> ActionCodeInfo

Copy a native FIRActionCodeInfo.

Parameters:

Name Type Description Default
native ObjCObject

the FIRActionCodeInfo.

required

ActionCodeOperation

What an email action code (link) is for. The values of ActionCodeInfo.operation.

ActionCodeSettings dataclass

ActionCodeSettings(
    url: str | None = None,
    handle_code_in_app: bool = False,
    ios_bundle_id: str | None = None,
    android_package_name: str | None = None,
    android_install_if_not_available: bool = False,
    android_minimum_version: str | None = None,
    link_domain: str | None = None,
)

Where email links (password reset, verification, sign-in) lead.

::

ActionCodeSettings(
    url="https://example.com/finish-sign-in",
    handle_code_in_app=True,
    ios_bundle_id="com.example.app",
)

Methods:

Name Description
to_native

Make the native FIRActionCodeSettings.

Attributes:

Name Type Description
url str | None

The continue URL: where the user lands after the action. Its domain must

handle_code_in_app bool

True to open the link in the app (required for email link sign-in).

ios_bundle_id str | None

The iOS app to open the link in.

android_package_name str | None

The Android app to open the link in.

android_install_if_not_available bool

Offer to install the Android app if it is missing.

android_minimum_version str | None

The minimum Android app version that can handle the link.

link_domain str | None

A custom Firebase Hosting domain for the link.

url class-attribute instance-attribute

url: str | None = None

The continue URL: where the user lands after the action. Its domain must be authorized in the Firebase console.

handle_code_in_app class-attribute instance-attribute

handle_code_in_app: bool = False

True to open the link in the app (required for email link sign-in).

ios_bundle_id class-attribute instance-attribute

ios_bundle_id: str | None = None

The iOS app to open the link in.

android_package_name class-attribute instance-attribute

android_package_name: str | None = None

The Android app to open the link in.

android_install_if_not_available class-attribute instance-attribute

android_install_if_not_available: bool = False

Offer to install the Android app if it is missing.

android_minimum_version class-attribute instance-attribute

android_minimum_version: str | None = None

The minimum Android app version that can handle the link.

link_domain: str | None = None

A custom Firebase Hosting domain for the link.

to_native

to_native() -> ObjCObject

Make the native FIRActionCodeSettings.

ActionCodeURL dataclass

ActionCodeURL(
    operation: int,
    code: str | None,
    continue_url: str | None,
    api_key: str | None,
    language_code: str | None,
)

The parts of an email action link (password reset, verification, sign-in), read without calling the server.

Use it to get the continue_url back, with the state you put in it ("Passing State in Email Actions")::

info = ActionCodeURL.from_link(link)
if info is not None and info.continue_url:
    state = urllib.parse.parse_qs(urllib.parse.urlsplit(info.continue_url).query)

Parsed in Python: Firebase iOS SDK 13.1.1 decodes the link's query before splitting it, which cuts a continue URL at its own & and loses state.

Methods:

Name Description
from_link

Parse an action link.

Attributes:

Name Type Description
operation int

An ActionCodeOperation value, from the link's mode.

code str | None

The action code (oobCode): pass it to apply_action_code,

continue_url str | None

The continue URL given in ActionCodeSettings.url, with its state.

api_key str | None

The Firebase API key in the link.

language_code str | None

The language of the email, or None.

operation instance-attribute

operation: int

An ActionCodeOperation value, from the link's mode.

code instance-attribute

code: str | None

The action code (oobCode): pass it to apply_action_code, confirm_password_reset, ...

continue_url instance-attribute

continue_url: str | None

The continue URL given in ActionCodeSettings.url, with its state.

api_key instance-attribute

api_key: str | None

The Firebase API key in the link.

language_code instance-attribute

language_code: str | None

The language of the email, or None.

from_link(link: str) -> ActionCodeURL | None

Parse an action link.

Links wrapped in another link's link parameter (as Firebase Hosting and Dynamic Links deliver them) are unwrapped.

Parameters:

Name Type Description Default
link str

the full link from the email (or the URL the app was opened with).

required

Returns:

Type Description
ActionCodeURL | None

An ActionCodeURL, or None if link has no mode or

ActionCodeURL | None

oobCode (it is not an action link).

AdditionalUserInfo dataclass

AdditionalUserInfo(
    provider_id: str,
    is_new_user: bool,
    username: str | None,
    profile: dict[str, Any],
)

Provider details from one sign-in.

Methods:

Name Description
from_native

Copy a native FIRAdditionalUserInfo.

Attributes:

Name Type Description
provider_id str

The provider used for this sign-in.

is_new_user bool

True if this sign-in created the account.

username str | None

The username at the provider (GitHub, Twitter), or None.

profile dict[str, Any]

The provider's profile data (for example Google's given_name).

provider_id instance-attribute

provider_id: str

The provider used for this sign-in.

is_new_user instance-attribute

is_new_user: bool

True if this sign-in created the account.

username instance-attribute

username: str | None

The username at the provider (GitHub, Twitter), or None.

profile instance-attribute

profile: dict[str, Any]

The provider's profile data (for example Google's given_name).

from_native classmethod

from_native(native: ObjCObject) -> AdditionalUserInfo

Copy a native FIRAdditionalUserInfo.

Parameters:

Name Type Description Default
native ObjCObject

the FIRAdditionalUserInfo.

required

AuthDataResult

AuthDataResult(native: ObjCObject)

The result of a sign-in, link or re-authentication.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRAuthDataResult.

required

Attributes:

Name Type Description
user User

The signed-in (or linked) user.

additional_user_info AdditionalUserInfo | None

Provider details from this sign-in, or None.

credential OAuthCredential | None

The OAuth credential the provider gave (OAuth providers only), or

user property

user: User

The signed-in (or linked) user.

additional_user_info property

additional_user_info: AdditionalUserInfo | None

Provider details from this sign-in, or None.

credential property

credential: OAuthCredential | None

The OAuth credential the provider gave (OAuth providers only), or None. Holds the provider's own access / ID tokens.

IDTokenResult dataclass

IDTokenResult(
    token: str,
    claims: dict[str, Any],
    expiration_date: datetime,
    issued_at_date: datetime,
    auth_date: datetime,
    sign_in_provider: str,
    sign_in_second_factor: str | None,
)

A Firebase ID token and what it says.

Methods:

Name Description
from_native

Copy a native FIRAuthTokenResult.

Attributes:

Name Type Description
token str

The ID token (a JWT). Send it to your backend to prove who the user is.

claims dict[str, Any]

All the token's claims, including custom claims set by your backend.

expiration_date datetime

When the token expires (UTC).

issued_at_date datetime

When the token was issued (UTC).

auth_date datetime

When the user signed in (UTC).

sign_in_provider str

The provider used to sign in, for example "password" or "anonymous".

sign_in_second_factor str | None

The second factor used, for multi-factor sign-in, or None.

token instance-attribute

token: str

The ID token (a JWT). Send it to your backend to prove who the user is.

claims instance-attribute

claims: dict[str, Any]

All the token's claims, including custom claims set by your backend.

expiration_date instance-attribute

expiration_date: datetime

When the token expires (UTC).

issued_at_date instance-attribute

issued_at_date: datetime

When the token was issued (UTC).

auth_date instance-attribute

auth_date: datetime

When the user signed in (UTC).

sign_in_provider instance-attribute

sign_in_provider: str

The provider used to sign in, for example "password" or "anonymous".

sign_in_second_factor instance-attribute

sign_in_second_factor: str | None

The second factor used, for multi-factor sign-in, or None.

from_native classmethod

from_native(native: ObjCObject) -> IDTokenResult

Copy a native FIRAuthTokenResult.

Parameters:

Name Type Description Default
native ObjCObject

the FIRAuthTokenResult.

required

UserInfo

UserInfo(native: ObjCObject)

A user's profile at one provider (an entry of User.provider_data).

Parameters:

Name Type Description Default
native ObjCObject

the native FIRUserInfo.

required

Attributes:

Name Type Description
provider_id str

The provider ID, for example "password" or "google.com".

uid str

The user's ID at that provider (not the Firebase uid).

display_name str | None

The name at that provider, or None.

email str | None

The email address at that provider, or None.

phone_number str | None

The phone number at that provider, or None.

photo_url str | None

The profile photo URL at that provider, or None.

provider_id property

provider_id: str

The provider ID, for example "password" or "google.com".

uid property

uid: str

The user's ID at that provider (not the Firebase uid).

display_name property

display_name: str | None

The name at that provider, or None.

email property

email: str | None

The email address at that provider, or None.

phone_number property

phone_number: str | None

The phone number at that provider, or None.

photo_url property

photo_url: str | None

The profile photo URL at that provider, or None.

UserMetadata dataclass

UserMetadata(
    creation_date: datetime | None,
    last_sign_in_date: datetime | None,
)

When the user was created and last signed in.

Methods:

Name Description
from_native

Copy a native FIRUserMetadata.

Attributes:

Name Type Description
creation_date datetime | None

When the account was created (UTC).

last_sign_in_date datetime | None

When the user last signed in (UTC).

creation_date instance-attribute

creation_date: datetime | None

When the account was created (UTC).

last_sign_in_date instance-attribute

last_sign_in_date: datetime | None

When the user last signed in (UTC).

from_native classmethod

from_native(native: ObjCObject) -> UserMetadata

Copy a native FIRUserMetadata.

Parameters:

Name Type Description Default
native ObjCObject

the FIRUserMetadata.

required

User

User(user: ObjCObject | None = None)

A Firebase user: the signed-in one by default.

User() reads the user who is signed in now. When nobody is, is_signed_in is False and the profile properties are None; the account methods need a signed-in user.

Get users from Auth.current_user, sign-in results and auth state listeners.

Parameters:

Name Type Description Default
user ObjCObject | None

a native FIRUser to wrap. Leave it out for the user who is signed in now.

None

Methods:

Name Description
get_id_token

Get a Firebase ID token, to prove who the user is to your backend.

get_id_token_result

Get a Firebase ID token and its claims (including custom claims).

reload

Fetch the user's latest profile from the server (for example to see

delete

Delete the account and sign the user out.

update_password

Change the password.

update_email

Change the email address right away, without verifying it.

update_profile

Change the display name and/or photo URL.

update_phone_number

Change the phone number, with a credential from PhoneAuthProvider.

send_email_verification

Email the user a link to verify their address.

send_email_verification_before_updating_email

Email a link to email; the address changes once the user opens it.

link_with_credential

Add a sign-in method to this account (for example turn an anonymous

link_with_provider

Link an OAuth provider through its web sign-in flow.

unlink

Remove a sign-in method from this account.

reauthenticate_with_credential

Sign in again with a fresh credential, before sensitive actions

reauthenticate_with_provider

Re-authenticate through an OAuth provider's web sign-in flow.

Attributes:

Name Type Description
auth ObjCObject

The native FIRAuth.

user ObjCObject | None

The native FIRUser, or None.

is_signed_in bool

True if this User holds a user.

uid str | None

The user's Firebase ID: unique and stable. Use it as your database key.

email str | None

The email address, or None.

display_name str | None

The display name, or None.

phone_number str | None

The phone number (E.164), or None.

photo_url str | None

The profile photo URL, or None.

provider_id str | None

Always "firebase" for a Firebase user.

is_anonymous bool

True for an anonymous user (Auth.sign_in_anonymously).

is_email_verified bool

True once the user has verified their email address.

provider_data list[UserInfo]

The user's profile at each linked provider (email, Google, ...).

metadata UserMetadata | None

When the account was created and last signed in, or None.

multi_factor MultiFactor

The user's second factors: list, enroll, unenroll.

tenant_id str | None

The tenant the user belongs to (multi-tenancy), or None.

refresh_token str | None

The refresh token. Keep it secret; you rarely need it.

auth instance-attribute

auth: ObjCObject = objc_class('FIRAuth').auth()

The native FIRAuth.

user instance-attribute

user: ObjCObject | None = (
    user if user is not None else self.auth.currentUser
)

The native FIRUser, or None.

is_signed_in property

is_signed_in: bool

True if this User holds a user.

uid property

uid: str | None

The user's Firebase ID: unique and stable. Use it as your database key.

email property

email: str | None

The email address, or None.

display_name property

display_name: str | None

The display name, or None.

phone_number property

phone_number: str | None

The phone number (E.164), or None.

photo_url property

photo_url: str | None

The profile photo URL, or None.

provider_id property

provider_id: str | None

Always "firebase" for a Firebase user.

is_anonymous property

is_anonymous: bool

True for an anonymous user (Auth.sign_in_anonymously).

is_email_verified property

is_email_verified: bool

True once the user has verified their email address.

provider_data property

provider_data: list[UserInfo]

The user's profile at each linked provider (email, Google, ...).

metadata property

metadata: UserMetadata | None

When the account was created and last signed in, or None.

multi_factor property

multi_factor: MultiFactor

The user's second factors: list, enroll, unenroll.

Raises:

Type Description
RuntimeError

no user is signed in.

tenant_id property

tenant_id: str | None

The tenant the user belongs to (multi-tenancy), or None.

refresh_token property

refresh_token: str | None

The refresh token. Keep it secret; you rarely need it.

get_id_token

get_id_token(
    callback: Callable[
        [str | None, AuthError | None], None
    ],
    force_refresh: bool = False,
) -> None

Get a Firebase ID token, to prove who the user is to your backend.

Parameters:

Name Type Description Default
callback Callable[[str | None, AuthError | None], None]

gets (token, None), or (None, error).

required
force_refresh bool

get a new token from the server even if the cached one is still valid (for example after custom claims changed).

False

Raises:

Type Description
RuntimeError

no user is signed in.

get_id_token_result

get_id_token_result(
    callback: Callable[
        [IDTokenResult | None, AuthError | None], None
    ],
    force_refresh: bool = False,
) -> None

Get a Firebase ID token and its claims (including custom claims).

Parameters:

Name Type Description Default
callback Callable[[IDTokenResult | None, AuthError | None], None]

gets (IDTokenResult, None), or (None, error).

required
force_refresh bool

get a new token from the server, for example after your backend changed the user's custom claims.

False

Raises:

Type Description
RuntimeError

no user is signed in.

reload

reload(callback: ErrorCallback | None = None) -> None

Fetch the user's latest profile from the server (for example to see is_email_verified change after they clicked the link).

Parameters:

Name Type Description Default
callback ErrorCallback | None

gets None or the error. Read the properties again after it.

None

Raises:

Type Description
RuntimeError

no user is signed in.

delete

delete(callback: ErrorCallback | None = None) -> None

Delete the account and sign the user out.

Parameters:

Name Type Description Default
callback ErrorCallback | None

gets None or the error. REQUIRES_RECENT_LOGIN means the user must re-authenticate first.

None

Raises:

Type Description
RuntimeError

no user is signed in.

update_password

update_password(
    password: str, callback: ErrorCallback | None = None
) -> None

Change the password.

Parameters:

Name Type Description Default
password str

the new password.

required
callback ErrorCallback | None

gets None or the error (WEAK_PASSWORD, REQUIRES_RECENT_LOGIN, ...).

None

Raises:

Type Description
RuntimeError

no user is signed in.

update_email

update_email(
    email: str, callback: ErrorCallback | None = None
) -> None

Change the email address right away, without verifying it.

Firebase rejects this when email enumeration protection is on (the default for new projects); use send_email_verification_before_updating_email.

Parameters:

Name Type Description Default
email str

the new email address.

required
callback ErrorCallback | None

gets None or the error.

None

Raises:

Type Description
RuntimeError

no user is signed in.

update_profile

update_profile(
    callback: ErrorCallback | None = None,
    *,
    display_name: str | None | _Unset = UNSET,
    photo_url: str | None | _Unset = UNSET,
) -> None

Change the display name and/or photo URL.

::

user.update_profile(on_done, display_name="Ada Lovelace")

Parameters:

Name Type Description Default
callback ErrorCallback | None

gets None or the error.

None
display_name str | None | _Unset

the new display name; None removes it; leave it out to keep it.

UNSET
photo_url str | None | _Unset

the new photo URL; None removes it; leave it out to keep it.

UNSET

Raises:

Type Description
RuntimeError

no user is signed in.

update_phone_number

update_phone_number(
    credential: AuthCredential,
    callback: ErrorCallback | None = None,
) -> None

Change the phone number, with a credential from PhoneAuthProvider.

Parameters:

Name Type Description Default
credential AuthCredential

a phone credential for the new number.

required
callback ErrorCallback | None

gets None or the error.

None

Raises:

Type Description
RuntimeError

no user is signed in.

send_email_verification

send_email_verification(
    callback: ErrorCallback | None = None,
    action_code_settings: ActionCodeSettings | None = None,
) -> None

Email the user a link to verify their address.

Parameters:

Name Type Description Default
callback ErrorCallback | None

gets None once the email is sent, or the error.

None
action_code_settings ActionCodeSettings | None

where the link leads, or None for the Firebase default page.

None

Raises:

Type Description
RuntimeError

no user is signed in.

send_email_verification_before_updating_email

send_email_verification_before_updating_email(
    email: str,
    callback: ErrorCallback | None = None,
    action_code_settings: ActionCodeSettings | None = None,
) -> None

Email a link to email; the address changes once the user opens it.

Parameters:

Name Type Description Default
email str

the new email address.

required
callback ErrorCallback | None

gets None once the email is sent, or the error.

None
action_code_settings ActionCodeSettings | None

where the link leads, or None.

None

Raises:

Type Description
RuntimeError

no user is signed in.

link_with_credential(
    credential: AuthCredential,
    callback: DataResultCallback | None = None,
) -> None

Add a sign-in method to this account (for example turn an anonymous user into an email/password one).

Parameters:

Name Type Description Default
credential AuthCredential

the credential to link.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error). CREDENTIAL_ALREADY_IN_USE means another account has it; error.updated_credential can sign in to that account.

None

Raises:

Type Description
RuntimeError

no user is signed in.

link_with_provider(
    provider: OAuthProvider,
    callback: DataResultCallback | None = None,
) -> None

Link an OAuth provider through its web sign-in flow.

Parameters:

Name Type Description Default
provider OAuthProvider

the provider, for example OAuthProvider("microsoft.com").

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error).

None

Raises:

Type Description
RuntimeError

no user is signed in.

unlink(
    provider_id: str,
    callback: Callable[
        [User | None, AuthError | None], None
    ]
    | None = None,
) -> None

Remove a sign-in method from this account.

Parameters:

Name Type Description Default
provider_id str

the provider to unlink, for example "google.com".

required
callback Callable[[User | None, AuthError | None], None] | None

gets (User, None) with the updated user, or (None, error) (NO_SUCH_PROVIDER if it was not linked).

None

Raises:

Type Description
RuntimeError

no user is signed in.

reauthenticate_with_credential

reauthenticate_with_credential(
    credential: AuthCredential,
    callback: DataResultCallback | None = None,
) -> None

Sign in again with a fresh credential, before sensitive actions (delete, update_password) that need a recent sign-in.

Parameters:

Name Type Description Default
credential AuthCredential

a credential for this same user.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error) (USER_MISMATCH for another user's credential).

None

Raises:

Type Description
RuntimeError

no user is signed in.

reauthenticate_with_provider

reauthenticate_with_provider(
    provider: OAuthProvider,
    callback: DataResultCallback | None = None,
) -> None

Re-authenticate through an OAuth provider's web sign-in flow.

Parameters:

Name Type Description Default
provider OAuthProvider

the provider the user signed in with.

required
callback DataResultCallback | None

gets (AuthDataResult, None), or (None, error).

None

Raises:

Type Description
RuntimeError

no user is signed in.

current_user

current_user() -> User | None

The signed-in User, or None. Same as Auth.auth().current_user.

sign_out

sign_out() -> AuthError | None

Sign the current user out of Firebase. Same as Auth.auth().sign_out().

Returns:

Type Description
AuthError | None

None, or the error.

pyios_firebase.auth.google

Google Sign-In, then Firebase Auth.

from pyios_firebase.auth.google import start_google_sign_in

def on_signed_in(result, error):
    if error is not None:
        if not error.cancelled:  # cancelled: the user closed the sheet
            print("Sign-in failed:", error.description)
        return
    print("Signed in:", result.user.uid)

start_google_sign_in(on_signed_in)

Needs the GoogleSignIn framework, and the reversed client ID URL scheme (com.googleusercontent.apps.YOUR-CLIENT-ID) in CFBundleURLTypes.

Functions:

Name Description
get_google_credential

Show the Google sign-in sheet and give back a Firebase credential,

start_google_sign_in

Show the Google sign-in sheet, then sign in to Firebase.

sign_out_of_google

Sign out of Google Sign-In, so the next sign-in shows the account picker.

on_gid_signin_handle_url

Give a URL the app was opened with to Google Sign-In.

on_gid_signin_handle_url_kivy

Kivy handler: Window.bind(on_drop_file=on_gid_signin_handle_url_kivy).

Attributes:

Name Type Description
GOOGLE_SIGN_IN_CANCELED Final

GIDSignInErrorCode.canceled: the user closed the Google sheet.

GOOGLE_SIGN_IN_DOMAIN Final

The error domain of Google Sign-In errors.

GOOGLE_SIGN_IN_CANCELED module-attribute

GOOGLE_SIGN_IN_CANCELED: Final = -5

GIDSignInErrorCode.canceled: the user closed the Google sheet.

GOOGLE_SIGN_IN_DOMAIN module-attribute

GOOGLE_SIGN_IN_DOMAIN: Final = 'com.google.GIDSignIn'

The error domain of Google Sign-In errors.

get_google_credential

get_google_credential(callback: CredentialCallback) -> None

Show the Google sign-in sheet and give back a Firebase credential, without signing in to Firebase (for example to link Google to the current user, or to re-authenticate).

Parameters:

Name Type Description Default
callback CredentialCallback

gets (credential, None), or (None, error). error.cancelled is True when the user closed the sheet.

required

start_google_sign_in

start_google_sign_in(
    callback: DataResultCallback, auth: Auth | None = None
) -> None

Show the Google sign-in sheet, then sign in to Firebase.

Parameters:

Name Type Description Default
callback DataResultCallback

gets (AuthDataResult, None), or (None, error). error.cancelled is True when the user closed the sheet: not a failure to report.

required
auth Auth | None

the Auth to sign in to (default: Auth.auth()).

None

sign_out_of_google

sign_out_of_google() -> None

Sign out of Google Sign-In, so the next sign-in shows the account picker.

Call it with Auth.sign_out(), which signs out of Firebase only.

on_gid_signin_handle_url

on_gid_signin_handle_url(url_string: str) -> bool

Give a URL the app was opened with to Google Sign-In.

Call it from your app's "open URL" handler. Newer Google Sign-In versions finish without it, so it is a safe backup.

Parameters:

Name Type Description Default
url_string str

the URL.

required

Returns:

Type Description
bool

True if Google Sign-In handled the URL; False if it is not a sign-in URL.

on_gid_signin_handle_url_kivy

on_gid_signin_handle_url_kivy(
    _window: Any, filename: str | bytes, *_args: Any
) -> None

Kivy handler: Window.bind(on_drop_file=on_gid_signin_handle_url_kivy).

Kivy (SDL) passes URLs the app was opened with as "dropped files"; this forwards them to on_gid_signin_handle_url.

Parameters:

Name Type Description Default
filename str | bytes

the URL, as Kivy passes it (bytes or str). The other arguments Kivy passes (the window, the position) are ignored.

required

pyios_firebase.auth.apple

Sign in with Apple, then Firebase Auth.

from pyios_firebase.auth.apple import start_apple_sign_in

def on_signed_in(result, error):
    if error is not None:
        if not error.cancelled:
            print(error.message or error.description)
        return
    print("Signed in:", result.user.uid, result.first_name)

start_apple_sign_in(on_signed_in)

Apple shares the name (and a real or relay email) only the FIRST time a user signs in to the app; later sign-ins give "" for those. The name is kept on the device until a Firebase sign-in carries it.

Needs the com.apple.developer.applesignin entitlement and the Apple provider enabled in the Firebase console (Authentication, Sign-in method).

Classes:

Name Description
AppleCredential

What Sign in with Apple gave, ready for Firebase.

AppleSignInResult

A Firebase sign-in with Apple: an AuthDataResult plus what Apple shared.

Functions:

Name Description
get_apple_credential

Show the Sign in with Apple sheet and give back a Firebase credential,

start_apple_sign_in

Show the Sign in with Apple sheet, then sign in to Firebase.

Attributes:

Name Type Description
AUTHORIZATION_ERROR_DOMAIN Final

The error domain of Apple's sign-in errors.

AUTHORIZATION_ERROR_UNKNOWN Final

Set-up problems, or no Apple Account on the device (also: the user closed

AUTHORIZATION_ERROR_CANCELED Final

ASAuthorizationErrorCanceled: the user closed the Apple sheet.

AUTHORIZATION_ERROR_DOMAIN module-attribute

AUTHORIZATION_ERROR_DOMAIN: Final = _string_constant(
    "ASAuthorizationErrorDomain",
    "com.apple.AuthenticationServices.AuthorizationError",
)

The error domain of Apple's sign-in errors.

AUTHORIZATION_ERROR_UNKNOWN module-attribute

AUTHORIZATION_ERROR_UNKNOWN: Final = 1000

Set-up problems, or no Apple Account on the device (also: the user closed iOS's "sign in to your Apple Account" alert).

AUTHORIZATION_ERROR_CANCELED module-attribute

AUTHORIZATION_ERROR_CANCELED: Final = 1001

ASAuthorizationErrorCanceled: the user closed the Apple sheet.

AppleCredential dataclass

AppleCredential(
    credential: OAuthCredential,
    apple_user: str,
    first_name: str,
    last_name: str,
    email: str,
    authorization_code: str,
)

What Sign in with Apple gave, ready for Firebase.

Attributes:

Name Type Description
credential OAuthCredential

The Firebase credential (provider "apple.com").

apple_user str

Apple's stable ID for the user in this app.

first_name str

The given name: only on the first sign-in to the app, else ""

last_name str

The family name: same rules as first_name.

email str

The email (real or private relay): only on the first sign-in, else "".

authorization_code str

A short-lived code: pass it to Auth.revoke_token before deleting the

credential instance-attribute

credential: OAuthCredential

The Firebase credential (provider "apple.com").

apple_user instance-attribute

apple_user: str

Apple's stable ID for the user in this app.

first_name instance-attribute

first_name: str

The given name: only on the first sign-in to the app, else "" (or the name kept from an earlier, failed attempt).

last_name instance-attribute

last_name: str

The family name: same rules as first_name.

email instance-attribute

email: str

The email (real or private relay): only on the first sign-in, else "".

authorization_code instance-attribute

authorization_code: str

A short-lived code: pass it to Auth.revoke_token before deleting the account (App Store rule).

AppleSignInResult

AppleSignInResult(
    native: ObjCObject, apple: AppleCredential
)

Bases: AuthDataResult

A Firebase sign-in with Apple: an AuthDataResult plus what Apple shared.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRAuthDataResult.

required
apple AppleCredential

what Apple gave for this sign-in.

required

Attributes:

Name Type Description
apple

What Apple gave (names, email, authorization code).

first_name str

The given name Apple shared (first sign-in only), else "".

last_name str

The family name Apple shared (first sign-in only), else "".

apple instance-attribute

apple = apple

What Apple gave (names, email, authorization code).

first_name property

first_name: str

The given name Apple shared (first sign-in only), else "".

last_name property

last_name: str

The family name Apple shared (first sign-in only), else "".

PyAppleSignInDelegate

Bases: NSObject

The ASAuthorizationController delegate and presentation context.

Rubicon reads these methods' annotations to build their Objective-C signatures: parameters must be annotated with ctypes types (objc_id), not Python types.

Methods:

Name Description
presentationAnchorForAuthorizationController_

The window the Apple sheet is shown over: the key window.

authorizationController_didCompleteWithAuthorization_

Apple signed the user in: turn the identity token into a credential.

authorizationController_didCompleteWithError_

Apple sign-in failed or was cancelled: report it.

presentationAnchorForAuthorizationController_

presentationAnchorForAuthorizationController_(
    controller: objc_id,
) -> objc_id

The window the Apple sheet is shown over: the key window.

authorizationController_didCompleteWithAuthorization_

authorizationController_didCompleteWithAuthorization_(
    controller: objc_id, authorization: objc_id
) -> None

Apple signed the user in: turn the identity token into a credential.

authorizationController_didCompleteWithError_

authorizationController_didCompleteWithError_(
    controller: objc_id, error: objc_id
) -> None

Apple sign-in failed or was cancelled: report it.

get_apple_credential

get_apple_credential(
    callback: AppleCredentialCallback,
) -> None

Show the Sign in with Apple sheet and give back a Firebase credential, without signing in to Firebase (for example to link Apple to the current user, or to re-authenticate before deleting the account).

Parameters:

Name Type Description Default
callback AppleCredentialCallback

gets (AppleCredential, None), or (None, error). error.cancelled is True when the user closed the sheet; error.message, when not "", is a sentence for the user.

required

start_apple_sign_in

start_apple_sign_in(
    callback: AppleSignInCallback, auth: Auth | None = None
) -> None

Show the Sign in with Apple sheet, then sign in to Firebase.

Parameters:

Name Type Description Default
callback AppleSignInCallback

gets (AppleSignInResult, None), or (None, error). error.cancelled is True when the user closed the sheet: not a failure to report. error.message, when not "", is a sentence to show to the user.

required
auth Auth | None

the Auth to sign in to (default: Auth.auth()).

None

pyios_firebase.auth.facebook

Facebook Login, then Firebase Auth.

from pyios_firebase.auth import facebook

facebook.initialize_facebook()          # once, at app start

def on_signed_in(result, error):
    if error is not None:
        if not error.cancelled:
            print("Sign-in failed:", error.description)
        return
    print("Signed in:", result.user.uid)

facebook.start_facebook_sign_in(on_signed_in)

Both of Facebook's login modes work:

  • classic login gives an access token (also usable with the Graph API);
  • Limited Login (limited=True, and what iOS falls back to when the user has not allowed tracking) gives an OpenID Connect token, checked with a nonce.

Needs the FacebookLogin framework (Swift package https://github.com/facebook/facebook-ios-sdk, product FacebookLogin), the Facebook provider enabled in the Firebase console, and in Info.plist: FacebookAppID, FacebookClientToken, FacebookDisplayName, the URL scheme fb<APP_ID>, and LSApplicationQueriesSchemes with fbapi and fb-messenger-share-api.

Functions:

Name Description
initialize_facebook

Start the Facebook SDK. Call it once, at app start (Facebook's

on_facebook_handle_url

Give a URL the app was opened with to the Facebook SDK (the login

on_facebook_handle_url_kivy

Kivy handler: Window.bind(on_drop_file=on_facebook_handle_url_kivy).

get_facebook_credential

Show Facebook Login and give back a Firebase credential, without signing

start_facebook_sign_in

Show Facebook Login, then sign in to Firebase.

sign_out_of_facebook

Log out of Facebook Login (the next login asks again).

Attributes:

Name Type Description
FACEBOOK_LOGIN_TRACKING_ENABLED Final

FBSDKLoginTrackingEnabled: classic login (an access token).

FACEBOOK_LOGIN_TRACKING_LIMITED Final

FBSDKLoginTrackingLimited: Limited Login (an OpenID Connect token).

FACEBOOK_LOGIN_TRACKING_ENABLED module-attribute

FACEBOOK_LOGIN_TRACKING_ENABLED: Final = 0

FBSDKLoginTrackingEnabled: classic login (an access token).

FACEBOOK_LOGIN_TRACKING_LIMITED module-attribute

FACEBOOK_LOGIN_TRACKING_LIMITED: Final = 1

FBSDKLoginTrackingLimited: Limited Login (an OpenID Connect token).

initialize_facebook

initialize_facebook() -> bool

Start the Facebook SDK. Call it once, at app start (Facebook's application(_:didFinishLaunchingWithOptions:) step).

Returns:

Type Description
bool

What the Facebook SDK returns (True when it started).

on_facebook_handle_url

on_facebook_handle_url(url_string: str) -> bool

Give a URL the app was opened with to the Facebook SDK (the login redirect back from the Facebook app or Safari).

Parameters:

Name Type Description Default
url_string str

the URL.

required

Returns:

Type Description
bool

True if the Facebook SDK handled it.

on_facebook_handle_url_kivy

on_facebook_handle_url_kivy(
    _window: Any, filename: str | bytes, *_args: Any
) -> None

Kivy handler: Window.bind(on_drop_file=on_facebook_handle_url_kivy).

Kivy (SDL) passes URLs the app was opened with as "dropped files"; this forwards them to on_facebook_handle_url.

Parameters:

Name Type Description Default
filename str | bytes

the URL, as Kivy passes it (bytes or str). The other arguments Kivy passes (the window, the position) are ignored.

required

get_facebook_credential

get_facebook_credential(
    callback: CredentialCallback,
    permissions: Sequence[str] = DEFAULT_PERMISSIONS,
    limited: bool = False,
) -> None

Show Facebook Login and give back a Firebase credential, without signing in to Firebase (for example to link Facebook to the current user).

Parameters:

Name Type Description Default
callback CredentialCallback

gets (credential, None), or (None, error). error.cancelled is True when the user cancelled.

required
permissions Sequence[str]

the Facebook permissions to ask for.

DEFAULT_PERMISSIONS
limited bool

True for Limited Login (no tracking). Facebook may also use Limited Login on its own when the user has not allowed tracking; both give a working credential.

False

start_facebook_sign_in

start_facebook_sign_in(
    callback: DataResultCallback,
    permissions: Sequence[str] = DEFAULT_PERMISSIONS,
    limited: bool = False,
    auth: Auth | None = None,
) -> None

Show Facebook Login, then sign in to Firebase.

Parameters:

Name Type Description Default
callback DataResultCallback

gets (AuthDataResult, None), or (None, error). error.cancelled is True when the user cancelled: not a failure to report. ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL means the email already has an account with another provider.

required
permissions Sequence[str]

the Facebook permissions to ask for.

DEFAULT_PERMISSIONS
limited bool

True for Limited Login (see get_facebook_credential).

False
auth Auth | None

the Auth to sign in to (default: Auth.auth()).

None

sign_out_of_facebook

sign_out_of_facebook() -> None

Log out of Facebook Login (the next login asks again).

Call it with Auth.sign_out(), which signs out of Firebase only.

pyios_firebase.auth.multi_factor

Multi-factor authentication: SMS and TOTP (authenticator app) second factors.

Enroll a second factor for the signed-in user::

mfa = auth.current_user.multi_factor
mfa.get_session(on_session)                       # 1. a session
PhoneAuthProvider().verify_phone_number(           # 2. SMS for enrollment
    "+15555550100", on_code_sent, multi_factor_session=session)
assertion = PhoneMultiFactorGenerator.assertion(phone.credential(verification_id, code))
mfa.enroll(assertion, "My phone", on_enrolled)     # 3. enroll

Sign in when a second factor is required::

def on_signed_in(result, error):
    if error is not None and error.code == AuthErrorCode.SECOND_FACTOR_REQUIRED:
        resolver = error.resolver                  # hints: the user's factors
        ...                                        # verify one, then:
        resolver.resolve_sign_in(assertion, on_signed_in)

Multi-factor needs Identity Platform (Firebase Authentication with Identity Platform) and the factor enabled in the console. Enrolling needs a verified email address.

Classes:

Name Description
MultiFactorSession

Proves the first factor was just completed (or that the user is signed

MultiFactorInfo

One enrolled second factor.

PhoneMultiFactorInfo

An enrolled SMS second factor.

MultiFactorAssertion

Proof of a second factor, for MultiFactor.enroll or

PhoneMultiFactorGenerator

Make SMS second-factor assertions.

TOTPSecret

A new TOTP secret, to show to the user while they set up their

TOTPMultiFactorGenerator

Make TOTP (authenticator app) secrets and assertions.

MultiFactor

A user's second factors. Get it with User.multi_factor.

MultiFactorResolver

Finishes a sign-in that needs a second factor. Get it from

Attributes:

Name Type Description
PHONE_FACTOR_ID Final

The factor_id of SMS second factors.

TOTP_FACTOR_ID Final

The factor_id of TOTP (authenticator app) second factors.

PHONE_FACTOR_ID module-attribute

PHONE_FACTOR_ID: Final = 'phone'

The factor_id of SMS second factors.

TOTP_FACTOR_ID module-attribute

TOTP_FACTOR_ID: Final = 'totp'

The factor_id of TOTP (authenticator app) second factors.

MultiFactorSession

MultiFactorSession(native: ObjCObject)

Proves the first factor was just completed (or that the user is signed in, for enrollment). Pass it to SMS verification or generate_secret.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorSession.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorSession.

native property

native: ObjCObject

The FIRMultiFactorSession.

MultiFactorInfo

MultiFactorInfo(native: ObjCObject)

One enrolled second factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorInfo.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorInfo.

uid str

The factor's ID (its enrollment ID for TOTP sign-in).

factor_id str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

display_name str | None

The name given at enrollment, or None.

enrollment_date datetime | None

When the factor was enrolled (UTC).

native property

native: ObjCObject

The FIRMultiFactorInfo.

uid property

uid: str

The factor's ID (its enrollment ID for TOTP sign-in).

factor_id property

factor_id: str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

display_name property

display_name: str | None

The name given at enrollment, or None.

enrollment_date property

enrollment_date: datetime | None

When the factor was enrolled (UTC).

PhoneMultiFactorInfo

PhoneMultiFactorInfo(native: ObjCObject)

Bases: MultiFactorInfo

An enrolled SMS second factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRPhoneMultiFactorInfo.

required

Attributes:

Name Type Description
phone_number str

The phone number, usually masked in sign-in hints (+*******0100).

phone_number property

phone_number: str

The phone number, usually masked in sign-in hints (+*******0100).

MultiFactorAssertion

MultiFactorAssertion(native: ObjCObject)

Proof of a second factor, for MultiFactor.enroll or MultiFactorResolver.resolve_sign_in. Make it with PhoneMultiFactorGenerator or TOTPMultiFactorGenerator.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorAssertion.

required

Attributes:

Name Type Description
native ObjCObject

The FIRMultiFactorAssertion.

factor_id str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

native property

native: ObjCObject

The FIRMultiFactorAssertion.

factor_id property

factor_id: str

PHONE_FACTOR_ID or TOTP_FACTOR_ID.

PhoneMultiFactorGenerator

Make SMS second-factor assertions.

Methods:

Name Description
assertion

An assertion from a phone credential.

assertion staticmethod

assertion(
    credential: AuthCredential,
) -> MultiFactorAssertion

An assertion from a phone credential.

Parameters:

Name Type Description Default
credential AuthCredential

from PhoneAuthProvider.credential after verify_phone_number (enrollment) or verify_phone_number_for_sign_in (sign-in).

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "phone".

TOTPSecret

TOTPSecret(native: ObjCObject)

A new TOTP secret, to show to the user while they set up their authenticator app.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRTOTPSecret.

required

Methods:

Name Description
shared_secret_key

The secret, to type into an authenticator app by hand.

generate_qr_code_url

An otpauth:// URL, to show as a QR code for an authenticator app.

open_in_otp_app

Open the URL in an installed authenticator app (if there is one).

Attributes:

Name Type Description
native ObjCObject

The FIRTOTPSecret.

native property

native: ObjCObject

The FIRTOTPSecret.

shared_secret_key

shared_secret_key() -> str

The secret, to type into an authenticator app by hand.

generate_qr_code_url

generate_qr_code_url(account_name: str, issuer: str) -> str

An otpauth:// URL, to show as a QR code for an authenticator app.

Parameters:

Name Type Description Default
account_name str

shown in the authenticator app, usually the email.

required
issuer str

your app's name, shown in the authenticator app.

required

Returns:

Type Description
str

The URL.

open_in_otp_app

open_in_otp_app(qr_code_url: str) -> None

Open the URL in an installed authenticator app (if there is one).

Parameters:

Name Type Description Default
qr_code_url str

from generate_qr_code_url.

required

TOTPMultiFactorGenerator

Make TOTP (authenticator app) secrets and assertions.

Methods:

Name Description
generate_secret

Make a new TOTP secret for enrollment.

assertion_for_enrollment

An assertion to enroll the authenticator app.

assertion_for_sign_in

An assertion to finish a sign-in with the authenticator app.

generate_secret staticmethod

generate_secret(
    session: MultiFactorSession,
    callback: Callable[
        [TOTPSecret | None, AuthError | None], None
    ],
) -> None

Make a new TOTP secret for enrollment.

Parameters:

Name Type Description Default
session MultiFactorSession

from MultiFactor.get_session.

required
callback Callable[[TOTPSecret | None, AuthError | None], None]

gets (TOTPSecret, None), or (None, error).

required

assertion_for_enrollment staticmethod

assertion_for_enrollment(
    secret: TOTPSecret, one_time_password: str
) -> MultiFactorAssertion

An assertion to enroll the authenticator app.

Parameters:

Name Type Description Default
secret TOTPSecret

from generate_secret.

required
one_time_password str

the 6-digit code the app shows now.

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "totp".

assertion_for_sign_in staticmethod

assertion_for_sign_in(
    enrollment_id: str, one_time_password: str
) -> MultiFactorAssertion

An assertion to finish a sign-in with the authenticator app.

Parameters:

Name Type Description Default
enrollment_id str

the uid of the TOTP hint in MultiFactorResolver.hints.

required
one_time_password str

the 6-digit code the app shows now.

required

Returns:

Type Description
MultiFactorAssertion

A MultiFactorAssertion with factor_id "totp".

MultiFactor

MultiFactor(native: ObjCObject)

A user's second factors. Get it with User.multi_factor.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactor.

required

Methods:

Name Description
get_session

Start an enrollment: get a session for SMS verification or a TOTP secret.

enroll

Enroll a second factor.

unenroll

Remove a second factor.

Attributes:

Name Type Description
enrolled_factors list[MultiFactorInfo]

The enrolled second factors (PhoneMultiFactorInfo for SMS).

enrolled_factors property

enrolled_factors: list[MultiFactorInfo]

The enrolled second factors (PhoneMultiFactorInfo for SMS).

get_session

get_session(
    callback: Callable[
        [MultiFactorSession | None, AuthError | None], None
    ],
) -> None

Start an enrollment: get a session for SMS verification or a TOTP secret.

Parameters:

Name Type Description Default
callback Callable[[MultiFactorSession | None, AuthError | None], None]

gets (MultiFactorSession, None), or (None, error) (REQUIRES_RECENT_LOGIN if the sign-in is old).

required

enroll

enroll(
    assertion: MultiFactorAssertion,
    display_name: str | None = None,
    callback: ErrorCallback | None = None,
) -> None

Enroll a second factor.

Parameters:

Name Type Description Default
assertion MultiFactorAssertion

from PhoneMultiFactorGenerator or TOTPMultiFactorGenerator.assertion_for_enrollment.

required
display_name str | None

a name to show in sign-in hints, for example "Work phone".

None
callback ErrorCallback | None

gets None or the error (UNVERIFIED_EMAIL if the email address is not verified yet).

None

unenroll

unenroll(
    factor: MultiFactorInfo | str,
    callback: ErrorCallback | None = None,
) -> None

Remove a second factor.

Parameters:

Name Type Description Default
factor MultiFactorInfo | str

the factor, or its uid.

required
callback ErrorCallback | None

gets None or the error. Removing the factor used to sign in signs the user out.

None

MultiFactorResolver

MultiFactorResolver(native: ObjCObject)

Finishes a sign-in that needs a second factor. Get it from AuthError.resolver when error.code == AuthErrorCode.SECOND_FACTOR_REQUIRED.

Parameters:

Name Type Description Default
native ObjCObject

the native FIRMultiFactorResolver.

required

Methods:

Name Description
resolve_sign_in

Finish the sign-in with a second factor.

Attributes:

Name Type Description
hints list[MultiFactorInfo]

The user's enrolled factors: let them choose one.

session MultiFactorSession

The session proving the first factor: pass it to SMS verification.

hints property

hints: list[MultiFactorInfo]

The user's enrolled factors: let them choose one.

session property

The session proving the first factor: pass it to SMS verification.

resolve_sign_in

resolve_sign_in(
    assertion: MultiFactorAssertion,
    callback: Callable[
        [AuthDataResult | None, AuthError | None], None
    ]
    | None = None,
) -> None

Finish the sign-in with a second factor.

Parameters:

Name Type Description Default
assertion MultiFactorAssertion

from PhoneMultiFactorGenerator.assertion or TOTPMultiFactorGenerator.assertion_for_sign_in.

required
callback Callable[[AuthDataResult | None, AuthError | None], None] | None

gets (AuthDataResult, None), or (None, error) (INVALID_VERIFICATION_CODE for a wrong code).

None