dnplus / streamlit-oauth

Simple OAuth Component for Streamlit App
MIT License
111 stars 18 forks source link

streamlit_oauth/frontend/dist read error when logged in #42

Closed namirinz closed 1 month ago

namirinz commented 1 month ago

The popup window appear and I can managed to login with getting a result token. But the window show read error text and when the log text from streamlit show read error

image

FYI my streamlit was deployed in Kubernetes.

My redirect URL: https://MYURL.com/component/streamlit_oauth.authorize_button

Error Message

2024-06-07 04:25:25.824 ComponentRequestHandler: GET /usr/local/lib/python3.10/site-packages/streamlit_oauth/frontend/dist read errorTraceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/streamlit/web/server/component_request_handler.py", line 54, in get with open(abspath, "rb") as file:IsADirectoryError: [Errno 21] Is a directory: '/usr/local/lib/python3.10/site-packages/streamlit_oauth/frontend/dist'

Dependency Version

streamlit-oauth           0.1.9
streamlit                 1.33.0

Streamlit Config

[browser]
gatherUsageStats = false

[server]
enableCORS = false
enableXsrfProtection = false
enableStaticServing = true

Streamlit Code

from streamlit_oauth import OAuth2Component

CLIENT_ID = os.getenv("AUTH_CLIENT_ID")
CLIENT_SECRET = os.getenv("AUTH_CLIENT_SECRET")
TOKEN_ENDPOINT = os.getenv("AUTH_TOKEN_ENDPOINT")
AUTHORIZE_ENDPOINT = os.getenv("AUTH_AUTHORIZE_ENDPOINT")
REDIRECT_URI = os.getenv("AUTH_REDIRECT_URI")

if "token" not in st.session_state:
    # create a button to start the OAuth2 flow
    st.write("Please login to continue (Please Enable Popup Window)")
    oauth2 = OAuth2Component(
        CLIENT_ID,
        CLIENT_SECRET,
        AUTHORIZE_ENDPOINT,
        TOKEN_ENDPOINT,
        TOKEN_ENDPOINT,
    )
    result = oauth2.authorize_button(
        name="Continue with OIDC Dex",
        icon="https://dexidp.io/favicons/favicon.png",
        redirect_uri=REDIRECT_URI,
        scope="openid",
        key="oidc",
        extras_params={"prompt": "consent", "access_type": "offline"},
        pkce="S256",
        auto_click=True,
    )
namirinz commented 1 month ago

Edited: Add redirect URL

dnplus commented 1 month ago

Hi @namirinz

Maybe you can try /component/streamlit_oauth.authorize_button/index.html see if work or not

We found there is some difference depends on deployment environment, it should be a problem from streamlit ComponentRequestHandler

36 in this case, with /index.html shows read error

But in my local environment without /index.html shows read error

namirinz commented 1 month ago

After adding /index.html in redirect uri. It's working with no any error now!

Thank you for your response.