streamlit-passwordless


Namestreamlit-passwordless JSON
Version 0.9.0 PyPI version JSON
download
home_pageNone
SummaryA user model for Streamlit applications based on passwordless technology.
upload_time2024-10-12 19:03:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License Copyright (c) 2023 Anton Lydell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords bitwarden fido2 passkey passwordless streamlit web webauthn
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            streamlit-passwordless
======================

|PyPI| |conda-forge| |conda-forge-platform| |Python| |LICENSE|


streamlit-passwordless provides a user model for Streamlit applications based on the Bitwarden
passwordless technology. It allows users to securely authenticate with a Streamlit application
using the passkey FIDO2 and WebAuthn protocols.

The project is under development and not yet ready for production. The library can handle
registering a new user by creating and registring a passkey with the user's device and
letting the user sign in with the passkey. The user model is not fully implemented yet.

A demo of the project is available at: https://passwordless.streamlit.app


Installation
------------

streamlit-passwordless is available on `PyPI`_ and `conda-forge`_ and can be installed with `pip`_
or `conda`_.

.. _conda: https://docs.conda.io/en/latest/
.. _conda-forge: https://anaconda.org/conda-forge/streamlit_passwordless
.. _pip: https://pip.pypa.io/en/stable/getting-started/
.. _PyPI: https://pypi.org/project/streamlit-passwordless/


Install with pip:

.. code-block:: bash

   $ pip install streamlit-passwordless


Install with conda:

.. code-block:: bash

   $ conda install conda-forge::streamlit_passwordless


License
-------

streamlit-passwordless is distributed under the `MIT-license`_.

.. _MIT-license: https://opensource.org/licenses/mit-license.php


Example
-------

Let's create an example Streamlit app using streamlit-passwordless. First create an account with
`Bitwarden Passwordless.dev`_ and make your *public* and *private* key accessable to your
application e.g. through a ".env" file, which we will use in this example. Create a new virtual
environment and install streamlit-passwordless. `python-dotenv`_ is also installed here to handle
loading the credentials for `Bitwarden Passwordless.dev`_.

.. _Bitwarden Passwordless.dev: https://admin.passwordless.dev/Account/Login
.. _python-dotenv: https://pypi.org/project/python-dotenv/


.. code-block:: bash

   ~ $ mkdir stp_demo && cd stp_demo
   ~/stp_demo $ echo ".env" > .gitignore
   ~/stp_demo $ python -m venv .venv
   ~/stp_demo $ source .venv/bin/activate
   ~/stp_demo (.venv) $ python -m pip install streamlit-passwordless python-dotenv


On Windows you should replace with ``source .venv/bin/activate`` with ``.venv/bin/Activate.ps1``.
The contents of the file *.env* is shown below. Replace ``<PUBLIC_KEY>`` and ``<PRIVATE_KEY>``
with your actual *public* and *private* key from Bitwarden Passwordless.dev. The *private key* is
called *secret key* in Bitwarden Passwordless.dev. Make sure the file *.env* is located in your
working directory *stp_demo*.


.. code-block::

   PUBLIC_KEY=<PUBLIC_KEY>
   PRIVATE_KEY=<PRIVATE_KEY>


Copy the code of the example app below into a file called *app.py* and place it in your
working directory *stp_demo*.


.. code-block:: python

   # app.py

   # Standard library
   import os
   from pathlib import Path

   # Third party
   import dotenv
   import streamlit as st
   import streamlit_passwordless as stp

   DOTENV_FILE = Path.cwd() / '.env'
   DB_URL = 'sqlite:///streamlit_passwordless.db'

   @st.cache_data
   def create_client(public_key: str, private_key: str) -> stp.BitwardenPasswordlessClient:
      r"""Create the client to connect to Bitwarden Passwordless backend API."""

      return stp.BitwardenPasswordlessClient(public_key=public_key, private_key=private_key)

   def main() -> None:
      r"""The main function to run the app."""

      st.title('Streamlit Passwordless Demo')
      st.markdown('## Register and Sign In')

      if not st.session_state:
         stp.init_session_state()  # Initialize the session state needed by streamlit-passwordless.

      dotenv.load_dotenv(DOTENV_FILE)  # Load the public and private key into environment variables.
      public_key, private_key = os.getenv('PUBLIC_KEY'), os.getenv('PRIVATE_KEY')

      if public_key is None or private_key is None:
         st.error('Public or private key not found in environment!', icon=stp.ICON_ERROR)
         return

      try:
         client = create_client(public_key=public_key, private_key=private_key)
      except stp.StreamlitPasswordlessError as e:
         st.error(str(e), icon=stp.ICON_ERROR)
         return

      session_factory = stp.db.create_session_factory(url=DB_URL)

      with session_factory() as session:
         register_tab, signin_in_tab = st.tabs(['Register', 'Sign in'])
         with register_tab:
            stp.bitwarden_register_form(client=client, db_session=session)
         with signin_in_tab:
            stp.bitwarden_sign_in_form(client=client, db_session=session)


   if __name__ == '__main__':
      main()


The app first initializes the session state variables needed by streamlit-passwordless.
Then it loads the public and private key from the *.env* file and creates the
``BitwardenPasswordlessClient``, which is used to communicate with Bitwarden Passwordless.dev.
The database session factory, needed to connect to the user database, is created from the cached
resource function `create_session_factory`. A SQLite database (streamlit_passwordless.db) located
in the current working directory is used in the example and if it does not exist it will be created.
Lastly the forms to *register* and *sign in* are rendered in separate tabs.
Run the example app with the following command:


.. code-block:: bash

   ~/stp_demo (.venv) $ python -m streamlit run app.py

   You can now view your Streamlit app in your browser.

   Local URL: http://localhost:8501


Open the url in your favorite web browser and try it out!

.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/streamlit_passwordless?style=plastic
   :alt: conda-forge - Version
   :target: https://anaconda.org/conda-forge/streamlit_passwordless


.. |conda-forge-platform| image:: https://img.shields.io/conda/pn/conda-forge/streamlit_passwordless?color=yellowgreen&style=plastic
   :alt: conda-forge - Platform
   :target: https://anaconda.org/conda-forge/streamlit_passwordless


.. |LICENSE| image:: https://img.shields.io/pypi/l/streamlit-passwordless?style=plastic
   :alt: PyPI - License
   :target: https://github.com/antonlydell/streamlit-passwordless/blob/main/LICENSE


.. |PyPI| image:: https://img.shields.io/pypi/v/streamlit-passwordless?style=plastic
   :alt: PyPI
   :target: https://pypi.org/project/streamlit-passwordless/


.. |Python| image:: https://img.shields.io/pypi/pyversions/streamlit-passwordless?style=plastic
   :alt: PyPI - Python Version
   :target: https://pypi.org/project/streamlit-passwordless/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "streamlit-passwordless",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "Bitwarden, FIDO2, Passkey, Passwordless, Streamlit, Web, WebAuthn",
    "author": null,
    "author_email": "Anton Lydell <anton.thedev@tuta.com>",
    "download_url": "https://files.pythonhosted.org/packages/08/b3/f5004ea9a76510f684762e952d67f22560ca98b4b94651792cbab0032a0d/streamlit_passwordless-0.9.0.tar.gz",
    "platform": null,
    "description": "streamlit-passwordless\n======================\n\n|PyPI| |conda-forge| |conda-forge-platform| |Python| |LICENSE|\n\n\nstreamlit-passwordless provides a user model for Streamlit applications based on the Bitwarden\npasswordless technology. It allows users to securely authenticate with a Streamlit application\nusing the passkey FIDO2 and WebAuthn protocols.\n\nThe project is under development and not yet ready for production. The library can handle\nregistering a new user by creating and registring a passkey with the user's device and\nletting the user sign in with the passkey. The user model is not fully implemented yet.\n\nA demo of the project is available at: https://passwordless.streamlit.app\n\n\nInstallation\n------------\n\nstreamlit-passwordless is available on `PyPI`_ and `conda-forge`_ and can be installed with `pip`_\nor `conda`_.\n\n.. _conda: https://docs.conda.io/en/latest/\n.. _conda-forge: https://anaconda.org/conda-forge/streamlit_passwordless\n.. _pip: https://pip.pypa.io/en/stable/getting-started/\n.. _PyPI: https://pypi.org/project/streamlit-passwordless/\n\n\nInstall with pip:\n\n.. code-block:: bash\n\n   $ pip install streamlit-passwordless\n\n\nInstall with conda:\n\n.. code-block:: bash\n\n   $ conda install conda-forge::streamlit_passwordless\n\n\nLicense\n-------\n\nstreamlit-passwordless is distributed under the `MIT-license`_.\n\n.. _MIT-license: https://opensource.org/licenses/mit-license.php\n\n\nExample\n-------\n\nLet's create an example Streamlit app using streamlit-passwordless. First create an account with\n`Bitwarden Passwordless.dev`_ and make your *public* and *private* key accessable to your\napplication e.g. through a \".env\" file, which we will use in this example. Create a new virtual\nenvironment and install streamlit-passwordless. `python-dotenv`_ is also installed here to handle\nloading the credentials for `Bitwarden Passwordless.dev`_.\n\n.. _Bitwarden Passwordless.dev: https://admin.passwordless.dev/Account/Login\n.. _python-dotenv: https://pypi.org/project/python-dotenv/\n\n\n.. code-block:: bash\n\n   ~ $ mkdir stp_demo && cd stp_demo\n   ~/stp_demo $ echo \".env\" > .gitignore\n   ~/stp_demo $ python -m venv .venv\n   ~/stp_demo $ source .venv/bin/activate\n   ~/stp_demo (.venv) $ python -m pip install streamlit-passwordless python-dotenv\n\n\nOn Windows you should replace with ``source .venv/bin/activate`` with ``.venv/bin/Activate.ps1``.\nThe contents of the file *.env* is shown below. Replace ``<PUBLIC_KEY>`` and ``<PRIVATE_KEY>``\nwith your actual *public* and *private* key from Bitwarden Passwordless.dev. The *private key* is\ncalled *secret key* in Bitwarden Passwordless.dev. Make sure the file *.env* is located in your\nworking directory *stp_demo*.\n\n\n.. code-block::\n\n   PUBLIC_KEY=<PUBLIC_KEY>\n   PRIVATE_KEY=<PRIVATE_KEY>\n\n\nCopy the code of the example app below into a file called *app.py* and place it in your\nworking directory *stp_demo*.\n\n\n.. code-block:: python\n\n   # app.py\n\n   # Standard library\n   import os\n   from pathlib import Path\n\n   # Third party\n   import dotenv\n   import streamlit as st\n   import streamlit_passwordless as stp\n\n   DOTENV_FILE = Path.cwd() / '.env'\n   DB_URL = 'sqlite:///streamlit_passwordless.db'\n\n   @st.cache_data\n   def create_client(public_key: str, private_key: str) -> stp.BitwardenPasswordlessClient:\n      r\"\"\"Create the client to connect to Bitwarden Passwordless backend API.\"\"\"\n\n      return stp.BitwardenPasswordlessClient(public_key=public_key, private_key=private_key)\n\n   def main() -> None:\n      r\"\"\"The main function to run the app.\"\"\"\n\n      st.title('Streamlit Passwordless Demo')\n      st.markdown('## Register and Sign In')\n\n      if not st.session_state:\n         stp.init_session_state()  # Initialize the session state needed by streamlit-passwordless.\n\n      dotenv.load_dotenv(DOTENV_FILE)  # Load the public and private key into environment variables.\n      public_key, private_key = os.getenv('PUBLIC_KEY'), os.getenv('PRIVATE_KEY')\n\n      if public_key is None or private_key is None:\n         st.error('Public or private key not found in environment!', icon=stp.ICON_ERROR)\n         return\n\n      try:\n         client = create_client(public_key=public_key, private_key=private_key)\n      except stp.StreamlitPasswordlessError as e:\n         st.error(str(e), icon=stp.ICON_ERROR)\n         return\n\n      session_factory = stp.db.create_session_factory(url=DB_URL)\n\n      with session_factory() as session:\n         register_tab, signin_in_tab = st.tabs(['Register', 'Sign in'])\n         with register_tab:\n            stp.bitwarden_register_form(client=client, db_session=session)\n         with signin_in_tab:\n            stp.bitwarden_sign_in_form(client=client, db_session=session)\n\n\n   if __name__ == '__main__':\n      main()\n\n\nThe app first initializes the session state variables needed by streamlit-passwordless.\nThen it loads the public and private key from the *.env* file and creates the\n``BitwardenPasswordlessClient``, which is used to communicate with Bitwarden Passwordless.dev.\nThe database session factory, needed to connect to the user database, is created from the cached\nresource function `create_session_factory`. A SQLite database (streamlit_passwordless.db) located\nin the current working directory is used in the example and if it does not exist it will be created.\nLastly the forms to *register* and *sign in* are rendered in separate tabs.\nRun the example app with the following command:\n\n\n.. code-block:: bash\n\n   ~/stp_demo (.venv) $ python -m streamlit run app.py\n\n   You can now view your Streamlit app in your browser.\n\n   Local URL: http://localhost:8501\n\n\nOpen the url in your favorite web browser and try it out!\n\n.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/streamlit_passwordless?style=plastic\n   :alt: conda-forge - Version\n   :target: https://anaconda.org/conda-forge/streamlit_passwordless\n\n\n.. |conda-forge-platform| image:: https://img.shields.io/conda/pn/conda-forge/streamlit_passwordless?color=yellowgreen&style=plastic\n   :alt: conda-forge - Platform\n   :target: https://anaconda.org/conda-forge/streamlit_passwordless\n\n\n.. |LICENSE| image:: https://img.shields.io/pypi/l/streamlit-passwordless?style=plastic\n   :alt: PyPI - License\n   :target: https://github.com/antonlydell/streamlit-passwordless/blob/main/LICENSE\n\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/streamlit-passwordless?style=plastic\n   :alt: PyPI\n   :target: https://pypi.org/project/streamlit-passwordless/\n\n\n.. |Python| image:: https://img.shields.io/pypi/pyversions/streamlit-passwordless?style=plastic\n   :alt: PyPI - Python Version\n   :target: https://pypi.org/project/streamlit-passwordless/\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Anton Lydell  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A user model for Streamlit applications based on passwordless technology.",
    "version": "0.9.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/antonlydell/streamlit-passwordless/issues",
        "Documentation": "https://github.com/antonlydell/streamlit-passwordless",
        "Source Code": "https://github.com/antonlydell/streamlit-passwordless"
    },
    "split_keywords": [
        "bitwarden",
        " fido2",
        " passkey",
        " passwordless",
        " streamlit",
        " web",
        " webauthn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d375e90931de7b0970021761a98abfe67fc121ca6efc4f5885c1135a4542f75",
                "md5": "c99bf295870abd1b7f8e997ad0af0890",
                "sha256": "3226ddfc50d696b5732498ad05efba2ab07280199fa73097bfb1224c18a00e86"
            },
            "downloads": -1,
            "filename": "streamlit_passwordless-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c99bf295870abd1b7f8e997ad0af0890",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 163362,
            "upload_time": "2024-10-12T19:03:55",
            "upload_time_iso_8601": "2024-10-12T19:03:55.054913Z",
            "url": "https://files.pythonhosted.org/packages/7d/37/5e90931de7b0970021761a98abfe67fc121ca6efc4f5885c1135a4542f75/streamlit_passwordless-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08b3f5004ea9a76510f684762e952d67f22560ca98b4b94651792cbab0032a0d",
                "md5": "47c416b304392ba2634b18e1e6ae7c0b",
                "sha256": "21289baba6e954284e8ffba986579ca77e959208058a5cf5fa14b9812590c1c8"
            },
            "downloads": -1,
            "filename": "streamlit_passwordless-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "47c416b304392ba2634b18e1e6ae7c0b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 155270,
            "upload_time": "2024-10-12T19:03:57",
            "upload_time_iso_8601": "2024-10-12T19:03:57.608460Z",
            "url": "https://files.pythonhosted.org/packages/08/b3/f5004ea9a76510f684762e952d67f22560ca98b4b94651792cbab0032a0d/streamlit_passwordless-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-12 19:03:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "antonlydell",
    "github_project": "streamlit-passwordless",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-passwordless"
}
        
Elapsed time: 0.48134s