streamlit-google-auth


Namestreamlit-google-auth JSON
Version 1.1.8 PyPI version JSON
download
home_pageNone
SummaryUse Google authentification in streamlit
upload_time2024-04-10 08:44:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.7
licenseMIT License Copyright (c) [year] [fullname] 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 streamlit google authentification
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Streamlit Google Auth
This package provides a simple and easy-to-use integration of Google authentication in your Streamlit application.

## Getting Started
1. Install the package:  
`pip install streamlit-google-auth`

2. Create a Google Cloud Platform project and obtain the client ID and client secret. You can follow the instructions [here](https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred) to create the credentials.

3. Save the client ID and client secret in a JSON file (e.g., google_credentials.json).

4. Import the necessary modules and initialize the Authenticate class:  
    ```python
    import streamlit as st
    from streamlit_google_auth import Authenticate

    authenticator = Authenticate(
        secret_credentials_path='google_credentials.json',
        cookie_name='my_cookie_name',
        cookie_key='this_is_secret',
        redirect_uri='http://localhost:8501',
    )
    ```

5. Check if the user is already authenticated and handle the login/logout flow:
    ```python
    # Check if the user is already authenticated
    authenticator.check_authentification()

    # Display the login button if the user is not authenticated
    if not st.session_state.get('connected', False):
        authorization_url = authenticator.get_authorization_url()
        st.markdown(f'[Login]({authorization_url})')
        st.link_button('Login', authorization_url)
    # Display the user information and logout button if the user is authenticated
    else:
        st.image(st.session_state['user_info'].get('picture'))
        st.write(f"Hello, {st.session_state['user_info'].get('name')}")
        st.write(f"Your email is {st.session_state['user_info'].get('email')}")
        if st.button('Log out'):
            authenticator.logout()
    ```

That's it! Your Streamlit app now has Google authentication integrated.

## Configuration
The Authenticate class takes the following parameters:

- `secret_credentials_path`: The path to the Google Cloud Platform credentials JSON file.
- `cookie_name`: The name of the cookie used to store the authentication information.
- `cookie_key`: The secret key used to encrypt the cookie.
- `redirect_uri`: The redirect URI of your Streamlit application.
- `cookie_expiry_days`: Optional, The number of days the cookie stay valid.

## Functions
The Authenticate class provides the following functions:
- `check_authentification()`: Catch the event when the user come back from the google login page and log it.
- `login()`: Displays the login button and handles the authentication flow.
- `logout()`: Logs out the user and clears the session state.
- `get_authorization_url()`: Returns the URL for the Google authentication page.

## Session State
The Authenticate class updates the following keys in the Streamlit session state:
- `connected`: A boolean indicating whether the user is authenticated or not.
- `oauth_id`: The unique identifier for the authenticated user.
- `user_info`: A dictionary containing the user's name, email, and profile picture URL.

## Example
Here's a complete example of how to use the Authenticate class in a Streamlit app:

```python
import streamlit as st
from streamlit_google_auth import Authenticate

st.title('Streamlit Google Auth Example')

if 'connected' not in st.session_state:
    authenticator = Authenticate(
        secret_credentials_path = 'google_credentials.json',
        cookie_name='my_cookie_name',
        cookie_key='this_is_secret',
        redirect_uri = 'http://localhost:8501',
    )
    st.session_state["authenticator"] = authenticator

# Catch the login event
st.session_state["authenticator"].check_authentification()

# Create the login button
st.session_state["authenticator"].login()

if st.session_state['connected']:
    st.image(st.session_state['user_info'].get('picture'))
    st.write('Hello, '+ st.session_state['user_info'].get('name'))
    st.write('Your email is '+ st.session_state['user_info'].get('email'))
    if st.button('Log out'):
        st.session_state["authenticator"].logout()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "streamlit-google-auth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.7",
    "maintainer_email": null,
    "keywords": "streamlit, google, authentification",
    "author": null,
    "author_email": "Adrien Bouvais <adrien.bouvais.pro@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/96/23/7fdca3d0cfe49892331c0fb957b06ce332324faed03988856da00b1ea1cf/streamlit-google-auth-1.1.8.tar.gz",
    "platform": null,
    "description": "# Streamlit Google Auth\nThis package provides a simple and easy-to-use integration of Google authentication in your Streamlit application.\n\n## Getting Started\n1. Install the package:  \n`pip install streamlit-google-auth`\n\n2. Create a Google Cloud Platform project and obtain the client ID and client secret. You can follow the instructions [here](https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred) to create the credentials.\n\n3. Save the client ID and client secret in a JSON file (e.g., google_credentials.json).\n\n4. Import the necessary modules and initialize the Authenticate class:  \n    ```python\n    import streamlit as st\n    from streamlit_google_auth import Authenticate\n\n    authenticator = Authenticate(\n        secret_credentials_path='google_credentials.json',\n        cookie_name='my_cookie_name',\n        cookie_key='this_is_secret',\n        redirect_uri='http://localhost:8501',\n    )\n    ```\n\n5. Check if the user is already authenticated and handle the login/logout flow:\n    ```python\n    # Check if the user is already authenticated\n    authenticator.check_authentification()\n\n    # Display the login button if the user is not authenticated\n    if not st.session_state.get('connected', False):\n        authorization_url = authenticator.get_authorization_url()\n        st.markdown(f'[Login]({authorization_url})')\n        st.link_button('Login', authorization_url)\n    # Display the user information and logout button if the user is authenticated\n    else:\n        st.image(st.session_state['user_info'].get('picture'))\n        st.write(f\"Hello, {st.session_state['user_info'].get('name')}\")\n        st.write(f\"Your email is {st.session_state['user_info'].get('email')}\")\n        if st.button('Log out'):\n            authenticator.logout()\n    ```\n\nThat's it! Your Streamlit app now has Google authentication integrated.\n\n## Configuration\nThe Authenticate class takes the following parameters:\n\n- `secret_credentials_path`: The path to the Google Cloud Platform credentials JSON file.\n- `cookie_name`: The name of the cookie used to store the authentication information.\n- `cookie_key`: The secret key used to encrypt the cookie.\n- `redirect_uri`: The redirect URI of your Streamlit application.\n- `cookie_expiry_days`: Optional, The number of days the cookie stay valid.\n\n## Functions\nThe Authenticate class provides the following functions:\n- `check_authentification()`: Catch the event when the user come back from the google login page and log it.\n- `login()`: Displays the login button and handles the authentication flow.\n- `logout()`: Logs out the user and clears the session state.\n- `get_authorization_url()`: Returns the URL for the Google authentication page.\n\n## Session State\nThe Authenticate class updates the following keys in the Streamlit session state:\n- `connected`: A boolean indicating whether the user is authenticated or not.\n- `oauth_id`: The unique identifier for the authenticated user.\n- `user_info`: A dictionary containing the user's name, email, and profile picture URL.\n\n## Example\nHere's a complete example of how to use the Authenticate class in a Streamlit app:\n\n```python\nimport streamlit as st\nfrom streamlit_google_auth import Authenticate\n\nst.title('Streamlit Google Auth Example')\n\nif 'connected' not in st.session_state:\n    authenticator = Authenticate(\n        secret_credentials_path = 'google_credentials.json',\n        cookie_name='my_cookie_name',\n        cookie_key='this_is_secret',\n        redirect_uri = 'http://localhost:8501',\n    )\n    st.session_state[\"authenticator\"] = authenticator\n\n# Catch the login event\nst.session_state[\"authenticator\"].check_authentification()\n\n# Create the login button\nst.session_state[\"authenticator\"].login()\n\nif st.session_state['connected']:\n    st.image(st.session_state['user_info'].get('picture'))\n    st.write('Hello, '+ st.session_state['user_info'].get('name'))\n    st.write('Your email is '+ st.session_state['user_info'].get('email'))\n    if st.button('Log out'):\n        st.session_state[\"authenticator\"].logout()\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [year] [fullname]  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": "Use Google authentification in streamlit",
    "version": "1.1.8",
    "project_urls": {
        "Homepage": "https://github.com/MrBounty/streamlit-google-auth"
    },
    "split_keywords": [
        "streamlit",
        " google",
        " authentification"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "daa6c530c084bfff54ce185b1e13386ccff43c610f6a2511638dbd2c7db0d99f",
                "md5": "4493facba8b85cd52166f25ac8cfbca5",
                "sha256": "5b3db4c769fcc51469046af85fd771c138e02629312dc58877bb8bbca91e9a83"
            },
            "downloads": -1,
            "filename": "streamlit_google_auth-1.1.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4493facba8b85cd52166f25ac8cfbca5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.7",
            "size": 7101,
            "upload_time": "2024-04-10T08:44:45",
            "upload_time_iso_8601": "2024-04-10T08:44:45.916916Z",
            "url": "https://files.pythonhosted.org/packages/da/a6/c530c084bfff54ce185b1e13386ccff43c610f6a2511638dbd2c7db0d99f/streamlit_google_auth-1.1.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96237fdca3d0cfe49892331c0fb957b06ce332324faed03988856da00b1ea1cf",
                "md5": "e85c25c21b2b22fba956c14c2147bce5",
                "sha256": "a844b07933d5e95b880bd72753b1ac9e07c8b62210ff5e3e3e69d48a3826883f"
            },
            "downloads": -1,
            "filename": "streamlit-google-auth-1.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e85c25c21b2b22fba956c14c2147bce5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.7",
            "size": 7303,
            "upload_time": "2024-04-10T08:44:47",
            "upload_time_iso_8601": "2024-04-10T08:44:47.276263Z",
            "url": "https://files.pythonhosted.org/packages/96/23/7fdca3d0cfe49892331c0fb957b06ce332324faed03988856da00b1ea1cf/streamlit-google-auth-1.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-10 08:44:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MrBounty",
    "github_project": "streamlit-google-auth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-google-auth"
}
        
Elapsed time: 0.42738s