Skip to content

Performance issue with auto_click=True? #53

@alp-yg

Description

@alp-yg

Hello,

Thanks a lot for the library, and the possibility to auto click on the login button.

However, it looks like that when using auto_click=True on the authorize_button, the button might be auto-clicked multiple times, including possibly in the popup window (aka the app starts normally, the popup window is opened, and instead of going to the auth page, it loads the app, including the button that is thus auto-clicked).

This results in multiple popup windows to be started, with some of them remaining after a successful login, with the app displayed in them. This also resulted in me unable to login as I most likely reached the max number of attempts 😄

It might be a performance issue as it does run fine some times.

Below is a code example with Microsoft auth (with secrets removed obviously):

import streamlit as st
from streamlit_oauth import OAuth2Component

tenantID = "<my_tenant_id>"

# Set environment variables
AUTHORIZE_URL = f"https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/authorize"
TOKEN_URL = f"https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token"
REFRESH_TOKEN_URL = f"https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/token"
REVOKE_TOKEN_URL = None
CLIENT_ID = "<my_client_id>"
CLIENT_SECRET = "<my_client_secret>"
REDIRECT_URI = "http://localhost:8501"
SCOPE = "openid"


# Create OAuth2Component instance
oauth2 = OAuth2Component(CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL, REFRESH_TOKEN_URL, REVOKE_TOKEN_URL)

# Check if token exists in session state
if 'token' not in st.session_state:
    # If not, show authorize button
    result = oauth2.authorize_button("Authorize", REDIRECT_URI, SCOPE, auto_click=True)
    if result and 'token' in result:
        # If authorization successful, save token in session state
        st.session_state.token = result.get('token')
        st.rerun()
else:
    # If token exists in session state, show the token
    token = st.session_state['token']
    st.json(token)
    if st.button("Refresh Token"):
        # If refresh token button is clicked, refresh the token
        token = oauth2.refresh_token(token)
        st.session_state.token = token
        st.rerun()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions