Skip to main content

Keycloak authentication for Streamlit

Project description

Streamlit Keycloak

Keycloak authentication inside your Streamlit app

Installation

pip install streamlit-keycloak

Usage

Creating a Keycloak component will perform authentication when the app is rendered. Credentials can be provided in the popup window. Outside of a SSO environment, you must allow popups to be able to log in.

The component returns a tuple containing the authentication state, OAuth2 token and user info respectively. If a refresh token is present, tokens are refreshed automatically. This will rerender the app.

Example

from streamlit_keycloak import keycloak
import streamlit as st


def main():
    st.subheader(f"Welcome {user_info['preferred_username']}!")
    st.write(f"Here is your OAuth2 token: {token}")


authenticated, token, user_info = keycloak(
    url="http://localhost:8080",
    realm="myrealm",
    client_id="myclient",
)

st.title("Streamlit Keycloak example")

if authenticated:
    main()

else:
    st.write("Authenticating...")

streamlit-keycloak showcase|639x663

Todo

  • Logout functionality?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit-keycloak-0.1.4.tar.gz (422.8 kB view hashes)

Uploaded Source

Built Distribution

streamlit_keycloak-0.1.4-py3-none-any.whl (429.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page