Got anyone a working example of an integration of
authentification with Keyclock into Streamlit?
I am able to authentificate when using login and password. But I do not want to deliver the login form in my application but like to redirect to the keycloak login form and go back to my application if login is correct.
So a access token has to be used. But after reading for hours I haven’t found the part dealing with the redirection to Keyclock and so on.
I was running into similar issues and came up with the following component: streamlit-keycloak
The component first attempts single sign on silently and if this fails, opens a popup to the keycloak login page. After logging in, authentication state, an oauth token and user info is available in the application.
Hopefully this also works for your use case. Feedback is always welcome.
As you know, I try your component and it’s usefull for me
I wanted to know how do you logout? I tried to add a disconnect button.
I tried some stuff like below without success: Probably because it attempts to sign on silently first.
from dataclasses import asdict
from streamlit_keycloak import login
import streamlit as st
def main():
st.subheader(f"Welcome {keycloak.user_info['preferred_username']}!")
st.write(f"Here is your user information:")
st.write(asdict(keycloak))
if st.button("Disconnect"):
keycloak.authenticated = False
st.title("Streamlit Keycloak example")
keycloak = login(
url="http://localhost:8080",
realm="myrealm",
client_id="myclient",
)
if keycloak.authenticated:
main()
Is there a proper way to logout with your component or the functionnality is not implemented?
Logging out is currently not implemented. The reasoning behind this is that a large use case for Keycloak is the single sign-on functionality. So signing out from the Streamlit app would also sign you put from all other services. So I reasoned Keycloak users wouldn’t be signing out that much.
It is on my todo list to implement this at some point though and keycloak-js provides functionality for doing this, but it might take a while until I get around to actually doing it.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.