streamlitextras.authenticator package

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

Pyrebase on PyPI seems to be missing latest commits - adding this in here. https://firebase.google.com/docs/reference/rest/auth#section-update-profile

class Authenticator(cookie_name: str, cookie_key: str, session_expiry_seconds: int = 1036800, session_name: str = 'user', authenticator_name: str = 'authenticator', user_class: Optional[Type[UserInherited]] = None, admin_ids: Optional[Union[list, str]] = None, developer_ids: Optional[Union[list, str]] = None, require_email_verification: bool = True, attempt_fallback_cookies: bool = False, debug: bool = False)[source]

Bases: object

Authenticator is used to handle firebase authentication, as well as create streamlit widgets for login, registration, and other account operations.

Parameters
  • authenticator_name (str) – named key for this Authenticator class, used to store it in session state. Used for tracking without classvar reference.

  • cookie_name (str) – the name of the auth cookie to be saved in the browser

  • cookie_key (str) – the key used to encrypt the JWT stored in the auth cookie

  • session_name (str) – the name of the key to store in st.session_state and the JWT token (with exp_date), containing the decoded auth cookie to

  • user_class (UserInherited) – Optional inherited User class to store the User state in

  • admins_ids (list) – List of firebase user ids (localId) used for checking User.is_admin Can also be | seperated string that will be parsed to a list - useful for parsing from a secrets config file

  • developer_ids (list) – List of firebase user ids (localId) used for checking User.is_developer Can also be | seperated string that will be parsed to a list - useful for parsing from a secrets config file

  • require_email_verification (bool) – If set to True (the default), users will not be able to log in until they verify their email address

delayed_init()[source]

Used to delay initialization of streamlit objects so this class can be cached

property logbind: dict
property service_auth: Optional[module]
property current_user: Optional[UserInherited]

Returns a User interface class instance if there is an active login

Gets the auth cookie

Returns

Returns the auth cookie or None if it doesnt exist

property auth_status: bool

First checks for any valid authentication cookies, then returns the current authentication status, True if a user is Authenticated, or else False.

Returns bool

The authentication status

set_form(form_name: Optional[str]) None[source]

Sets a variable to keep track of which form is currently displayed.

“login” = Login form “register” = Registration form “reset_password” = Reset password form

logout(button_name: str, button_location: Union[DeltaGenerator, module] = DeltaGenerator(_root_container=1, _parent=DeltaGenerator()), disabled: bool = False) bool[source]

Creates a logout button.

Parameters
  • button_name (str) – The rendered name of the logout button.

  • button_location (Union[DeltaGenerator, ModuleType]) – The streamlit container to place the button. Either global st or a st container object such as st.sidebar.

  • disabled (bool) – Passed to the streamlit button disabled kwarg, to optional disable the button in some circumstances. Default is False.

Returns bool

Returns True when clicked

login(form_name: str, form_location: ~typing.Union[~streamlit.delta_generator.DeltaGenerator, module] = <module 'streamlit' from '/home/docs/checkouts/readthedocs.org/user_builds/streamlitextras/envs/latest/lib/python3.10/site-packages/streamlit/__init__.py'>, success_callback: ~typing.Optional[~typing.Callable] = None, cb_args: ~typing.Optional[tuple] = None, cb_kwargs: ~typing.Optional[dict] = None) Tuple[Optional[UserInherited], dict, Optional[LoginError]][source]

Creates a login widget.

Parameters
  • form_name (str) – The rendered name of the login form.

  • form_location (Union[DeltaGenerator, ModuleType]) – The streamlit container to place the form. Either global st or a st container object such as st.sidebar.

  • success_callback (Callable) – Optional function to call if a user is created without error. Will be passed a kwargs login_return which will be the same tuple returned from this login function.

  • cb_args – Extra args for success_callback

  • cb_kwargs – Extra keyword args for success_callback

Returns

3 element tuple containing the a User class if one was created, response from the firebase calls, and/or any errors

register_user(form_name: str, form_location: ~typing.Union[~streamlit.delta_generator.DeltaGenerator, module] = <module 'streamlit' from '/home/docs/checkouts/readthedocs.org/user_builds/streamlitextras/envs/latest/lib/python3.10/site-packages/streamlit/__init__.py'>, terms_link: ~typing.Optional[str] = None) Tuple[Optional[dict], Optional[RegisterError]][source]

Creates a user registration widget

Parameters
  • form_name (str) – The rendered name of the password reset form.

  • form_location (Union[DeltaGenerator, ModuleType]) – The streamlit container to place the form. Either global st or a st container object such as st.sidebar.

Returns

tuple containing the firebase response and any errors

reset_password(form_name: str, form_location: ~typing.Union[~streamlit.delta_generator.DeltaGenerator, module] = <module 'streamlit' from '/home/docs/checkouts/readthedocs.org/user_builds/streamlitextras/envs/latest/lib/python3.10/site-packages/streamlit/__init__.py'>) Tuple[Optional[dict], Optional[ResetError]][source]

Creates a reset password via email widget.

Parameters
  • form_name (str) – The rendered name of the reset password form.

  • form_location (Union[DeltaGenerator, ModuleType]) – The streamlit container to place the form. Either global st or a st container object such as st.sidebar.

Returns

tuple containing the firebase response and any errors

get_auth(cookie_name: str, user_class: Optional[UserInherited] = None, authenticator_name='authenticator', **kwargs) Authenticator[source]

See Authenticator for params.

Submodules

streamlitextras.authenticator.exceptions module

exception AuthException(message: str, firebase_error: Optional[str] = None, requests_exception: Optional[Union[HTTPError, Exception]] = None)[source]

Bases: Exception

Base exception for Authenticator class

exception LoginError(message: str, firebase_error: Optional[str] = None, requests_exception: Optional[Union[HTTPError, Exception]] = None)[source]

Bases: AuthException

Exceptions raised for the login user widget.

exception RegisterError(message: str, firebase_error: Optional[str] = None, requests_exception: Optional[Union[HTTPError, Exception]] = None)[source]

Bases: AuthException

Exceptions raised for the register user widget.

exception ResetError(message: str, firebase_error: Optional[str] = None, requests_exception: Optional[Union[HTTPError, Exception]] = None)[source]

Bases: AuthException

Exceptions raised for the rest password widget.

exception UpdateError(message: str, firebase_error: Optional[str] = None, requests_exception: Optional[Union[HTTPError, Exception]] = None)[source]

Bases: AuthException

Exceptions raised for the update user details widget.

streamlitextras.authenticator.user module

class User(authenticator, auth_data, login_data={}, debug: bool = False)[source]

Bases: object

This class is used as an interface for Authenticators users

refresh_token()[source]
property firebase_user

Gets the UserRecord object from the official firebase python SDK

# https://firebase.google.com/docs/reference/admin/python/firebase_admin.auth#firebase_admin.auth.UserRecord

property is_admin

Returns true if users firebase id is in self.authenticator.admin_ids

property is_developer

Returns true if users firebase id is in self.authenticator.developer_ids

streamlitextras.authenticator.utils module

handle_firebase_action(action_function, exception_type, error_dict, *fn_args, **fn_kwargs)[source]

Handler for pyrebase/firebase actions.