Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default example at OIDC implementation giving some errors #1229

Open
ug0x01 opened this issue Feb 8, 2025 · 5 comments
Open

Default example at OIDC implementation giving some errors #1229

ug0x01 opened this issue Feb 8, 2025 · 5 comments

Comments

@ug0x01
Copy link

ug0x01 commented Feb 8, 2025

Hello,

I reviewed the docs about OIDC implementation but it gives some errors, can you just write an example of implementation of OIDC?

import streamlit as st

if not st.experimental_user.is_logged_in:
    st.header("Log in:")
    if st.button("Microsoft"):
        st.login("microsoft")
    if st.button("Okta"):
        st.login("okta")
else:
    if st.button("Log out"):
        st.logout()
    st.write(f"Hello, {st.experimental_user.name}!")

I just copy-pasted this code and tried to run it with streamlit run file.py and got the error;

File "/root/streamlit/file.py", line 3, in <module>
    if not st.experimental_user.is_logged_in:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/share/pipx/venvs/streamlit/lib/python3.12/site-packages/streamlit/user_info.py", line 72, in __getattr__
    raise AttributeError```

Thanks!

@ug0x01 ug0x01 added bug Something isn't working needs triage labels Feb 8, 2025
@sfc-gh-dmatthews
Copy link
Contributor

sfc-gh-dmatthews commented Feb 8, 2025

Do you have authentication configured? You need to have an [auth] dictionary in secrets.toml for st.experimental_user to have the is_logged_in attribute. See the attribute description here: https://docs.streamlit.io/develop/api-reference/user/st.user

@kajarenc @jrieke Since st.experimental_user no longer reads the email from Community Cloud, should we also change this conditional behavior so that is_logged_in always exists for local apps?

@ug0x01
Copy link
Author

ug0x01 commented Feb 9, 2025

Hello @sfc-gh-dmatthews,

I don't have a secrets.toml file, so I tried to use directly

import streamlit as st

if st.button("Microsoft"):
    st.login("microsoft")
if st.button("Okta"):
    st.login("okta")

And got this error:

AttributeError: module 'streamlit' has no attribute 'login'
Traceback:

File "/root/streamlit/e2e_playwright/shared/ehe.py", line 4, in <module>
    st.login("microsoft")
    ^^^^^^^^

@sfc-gh-dmatthews
Copy link
Contributor

sfc-gh-dmatthews commented Feb 9, 2025

st.login won't work without the configuration in secrets.toml. Also, if st.login is not found, make sure you have upgraded the version of Streamlit.

The examples provide an example TOML file to use for secrets.toml alongside the code. However, to use them, you need to set up an application in another system (your identity provider). It's not possible to have a standalone working example in Streamlit.

A conceptual guide is available here: https://docs.streamlit.io/develop/concepts/connections/authentication

Tutorials for some specific identity providers will be coming soon. A PR is started here: #1228

@ug0x01
Copy link
Author

ug0x01 commented Feb 9, 2025

Hello @sfc-gh-dmatthews,

My streamlit version is 1.41.1 and I removed and reinstalled to make sure it's the last version but still says module 'streamlit' has no attribute 'login' and I don't think it's about the auth settings

@sfc-gh-dmatthews
Copy link
Contributor

sfc-gh-dmatthews commented Feb 9, 2025

You need version 1.42.0 which was just released this week. Can you pip install streamlit -U? While your app is running, in the upper right corner, in the app menu under "About," you can confirm the Streamlit version that the app is using. You can also include a check in your app:

import streamlit as st
st.write(st.__version__)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants