Streamlit cloud bug? - streamlit-oauth package

I’ve got the exact same problem as described in this topic, but it is closed, so I can’t answer there (maybe re-open?)

The link to the github repository of the package is: GitHub - dnplus/streamlit-oauth: Simple OAuth Component for Streamlit App

minimum reproducable code:

config.toml

[logger]
level = 'debug'

[server]
enableStaticServing = true

[runner]
fastReruns = false

main.py

import streamlit as st
from streamlit_oauth import OAuth2Component

# Set environment variables
kadiApiBaseURL = 'https://kadi4mat.iam.kit.edu'
AUTHORIZE_URL = kadiApiBaseURL + '/oauth/authorize'
TOKEN_URL = kadiApiBaseURL + '/oauth/token'
REFRESH_TOKEN_URL = kadiApiBaseURL + '/oauth/token'
REVOKE_TOKEN_URL = kadiApiBaseURL + '/oauth/revoke'
CLIENT_ID = st.secrets['oauthClientID']
CLIENT_SECRET = st.secrets['oauthClientSecret']
REDIRECT_URI = 'https://[[**YOUR APP**]].streamlit.app/component/streamlit_oauth.authorize_button/index.html'
SCOPE = ''

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

result = oauth2.authorize_button("Authorize", REDIRECT_URI, SCOPE, height=800, width=400, use_container_width=True, extras_params={'response_type': 'code'})
if result and 'token' in result:
    # If authorization successful, save token in session state
    st.session_state.token = result.get('token')
    st.rerun()

Since I assume you don’t have a Kadi4Mat account, this is the log after clicking on “Authorize” - streamlit loads the redirect and gives “read error” in the popup afterwards. I think this can be reproduced with other URLs as well

streamlit console log

2024-04-26 13:09:20.502 Registered component 'streamlit_oauth.authorize_button': /home/adminuser/venv/lib/python3.12/site-packages/streamlit_oauth/frontend/dist

2024-04-26 13:09:20.508 Creating new DataCache (key=#####data cache key####, persist=None, max_entries=None, ttl=300)

2024-04-26 13:09:20.508 Cache key: #####some key####

2024-04-26 13:09:20.509 Memory cache MISS: #####some key####

2024-04-26 13:09:20.509 Memory cache MISS: #####some key####

2024-04-26 13:09:20.509 Memory cache MISS: #####some key####

2024-04-26 13:09:20.916 Removing orphaned files...

2024-04-26 13:09:21.017 Script run finished successfully; removing expired entries from MessageCache (max_age=2)

2024-04-26 13:09:38.887 ComponentRequestHandler: GET /home/adminuser/venv/lib/python3.12/site-packages/streamlit_oauth/frontend/dist read error

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.12/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: '/home/adminuser/venv/lib/python3.12/site-packages/streamlit_oauth/frontend/dist'
2 Likes

We are experiencing the exact same bugg, the “read error” pops up briefly. It is not a breaking bugg, but it doesn’t look nice.

Any solution on how to fix this?

Update: Although the docs state that one should add the "component/streamlit_oauth.authorize_button/index.html’ to the URL, this actually seem to be the cause of the problem. Once removing this part, the issue is no longer. It is described here: "read error" issue during successfull authorization · Issue #45 · dnplus/streamlit-oauth · GitHub

I know you’ve found a solution, I just wanted to add the link to the issue that I opened on github to solve this: 'read error' after authorizing in Popup on streamlit cloud · Issue #36 · dnplus/streamlit-oauth · GitHub
also see
streamlit_oauth/frontend/dist read error when logged in · Issue #42 · dnplus/streamlit-oauth · GitHub

As you wrote, remove the „/index.html“ from this part (some example on dnplus‘ github was with this):

REDIRECT_URI = 'https://[[**YOUR APP**]].streamlit.app/component/streamlit_oauth.authorize_button/index.html'

so that it is:

REDIRECT_URI = 'https://[[**YOUR APP**]].streamlit.app/component/streamlit_oauth.authorize_button'

and reboot the app. Worked fine for me.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.