firebase.auth package

A simple python wrapper for Google’s Firebase Authentication REST API

class firebase.auth.Auth(api_key, credentials, requests, client_secret=None)[source]

Bases: object

Firebase Authentication Service

Parameters:
  • api_key (str) – apiKey from Firebase configuration

  • credentials (Credentials) – Service Account Credentials

  • requests (Session) – Session to make HTTP requests

  • client_secret (str or dict) – (Optional) File path to or the dict object from social client secret file, defaults to None.

authenticate_login_with_facebook()[source]

Redirect the user to Facebook’s OAuth 2.0 server to initiate the authentication and authorization process.

Returns:

Facebook Sign In URL

Return type:

str

authenticate_login_with_google()[source]

Redirect the user to Google’s OAuth 2.0 server to initiate the authentication and authorization process.

Returns:

Google Sign In URL

Return type:

str

change_email(id_token, email)[source]

Changes a user’s email

Parameters:
  • id_token (str) – A Firebase Auth ID token for the user.

  • email (str) – User’s new email.

Returns:

UserInfo and Firebase Auth Tokens.

Return type:

dict

change_password(id_token, password)[source]

Changes a user’s password

Parameters:
  • id_token (str) – A Firebase Auth ID token for the user.

  • password (str) – User’s new password.

Returns:

UserInfo and Firebase Auth Tokens.

Return type:

dict

create_authentication_uri(provider_id)[source]

Creates an authentication URI for the given social provider.

Parameters:

provider_id (str) – The IdP ID. For white listed IdPs it’s a short domain name e.g. ‘google.com’, ‘aol.com’, ‘live.net’ and ‘yahoo.com’. For other OpenID IdPs it’s the OP identifier.

Returns:

The URI used by the IDP to authenticate the user.

Return type:

str

create_custom_token(uid, additional_claims=None, expiry_minutes=60)[source]

Create a Firebase Auth custom token.

Parameters:
  • uid (str) – The unique identifier of the user, must be a string, between 1-36 characters long.

  • additional_claims (dict or None) – Optional custom claims to include in the Security Rules auth / request.auth variables.

  • expiry_minutes (int) – The time, in minutes since the UNIX epoch, at which the token expires. Default value is 60.

Returns:

Firebase Auth custom token.

Return type:

str

create_user_with_email_and_password(email, password)[source]

Create a new user with email and password.

Parameters:
  • email (str) – The email for the user to create.

  • password (str) – The password for the user to create.

Returns:

User Email and Firebase Auth Tokens.

Return type:

dict

delete_user_account(id_token)[source]

Delete an existing user.

Parameters:

id_token (str) – The Firebase ID token of the user to delete.

get_account_info(id_token)[source]

Fetch user’s stored account information.

Parameters:

id_token (str) – The Firebase ID token of the account.

Returns:

The account info, associated with the given Firebase ID token.

Return type:

dict

refresh(refresh_token)[source]

Refresh a Firebase ID token.

Parameters:

refresh_token (str) – A Firebase Auth refresh token.

Returns:

New (Refreshed) Firebase Auth tokens for the account.

Return type:

dict

send_email_verification(id_token)[source]

Send an email verification to verify email ownership.

Parameters:

id_token (str) – The Firebase ID token of the user to verify.

Returns:

The email of the account associated with Firebase ID token.

Return type:

dict

send_password_reset_email(email)[source]

Send a password reset email.

Parameters:

email (str) – User’s email address.

Returns:

User’s email address.

Return type:

dict

set_custom_user_claims(user_id, custom_claims)[source]

Add or remove custom claims from/to an existing user.

Parameters:
  • user_id (str) – Firebase User UID.

  • custom_claims (dict) – Claims to add to that user’s token.

sign_in_anonymous()[source]

Sign In Anonymously.

Returns:

Firebase Auth Tokens.

Return type:

dict

sign_in_with_custom_token(token)[source]

Exchange custom token for an ID and refresh token.

Parameters:

token (str) – A Firebase Auth custom token from which to create an ID and refresh token pair.

Returns:

Firebase Auth Tokens.

Return type:

dict

sign_in_with_email_and_password(email, password)[source]

Sign in a user with an email and password.

Parameters:
  • email (str) – The email the user is signing in with.

  • password (str) – The password for the account.

Returns:

UserInfo and Firebase Auth Tokens.

Return type:

dict

sign_in_with_oauth_credential(oauth2callback_url)[source]

Sign In With OAuth credential.

Parameters:

oauth2callback_url (str) – The URL redirected to after successful authorization from the provider.

Returns:

User account info and Firebase Auth Tokens.

Return type:

dict

update_profile(id_token, display_name=None, photo_url=None, delete_attribute=None)[source]

Update a user’s profile (display name / photo URL).

Parameters:
  • id_token (str) – A Firebase Auth ID token for the user.

  • display_name (str or None) – User’s new display name.

  • photo_url (None or str) – User’s new photo url.

  • delete_attribute (list[str] or None) – List of attributes to delete, “DISPLAY_NAME” or “PHOTO_URL”. This will nullify these values.

Returns:

UserInfo and Firebase Auth Tokens.

Return type:

dict

verify_id_token(id_token)[source]

Decode Firebase Auth ID token.

Parameters:

id_token (str) – A Firebase Auth ID token for the user.

Returns:

Decoded claims of Firebase Auth ID token.

Return type:

dict

verify_password_reset_code(reset_code, new_password)[source]

Reset password using code.

Parameters:
  • reset_code (str) – The email action code sent to the user’s email for resetting the password.

  • new_password (str) – The user’s new password.

Returns:

User Email and Type of the email action code.

Return type:

dict