PropelAuth Logo

Streamlit Authentication/Authorization with PropelAuth

Streamlit Authentication/Authorization with PropelAuth

Streamlit is an open-source Python framework that makes it incredibly easy for data scientists and machine learning engineers to create interactive web applications from their existing Python scripts. Think of it as a magic wand that transforms your Python code into a beautiful web app - even if your CSS skills are limited.

And while Streamlit is known for its ease of use, protecting a Streamlit app with Authentication and Authorization is limited. That’s why we’re happy to announce our support for Streamlit, complete with all that makes PropelAuth great - organizations, role based access control, multiple login methods, and more.

Haven’t we done this before?

If this all seems familiar, you’re right! About a year ago we announced a previous integration with Streamlit. While this integration allowed many of our Python-loving customers to protect their Streamlit apps, we knew that we could make our integration simpler, more straightforward, and even more powerful.

This time around, we’re using Streamlit’s new OpenID Connect (OIDC) support to integrate with PropelAuth. Now, integrating PropelAuth only takes a few minutes and only takes a few lines of code:

if st.experimental_user.is_logged_in:
    user = auth.get_user(st.experimental_user.sub)
    if user:
        st.write(user)
else:
    st.login()

So what’s different?

This time around we wanted to focus on one of PropelAuth’s most powerful features - Role Based Access Control (RBAC). Combining the ease of use of both Streamlit and PropelAuth, protecting resources based on a user’s role and permissions within an organization is now simpler than ever.

def return_org_name(org):
    return org.org_name

if st.experimental_user.is_logged_in:
    user = auth.get_user(st.experimental_user.sub)
    org = st.selectbox(
	    "Select an organization", 
	    user.get_orgs(), 
	    format_func=return_org_name
	  )
    permission_to_check = "can_view_protected_data"
    if org and org.user_has_permission(permission_to_check):
        st.write(f"You can view this data for org {org.org_name}")
    else:
        st.write("You do not have the necessary permission to view this data.")

Let’s get going!

Eager to get started? Whether you’re looking for organization management, MFA, SAML, or user impersonation, getting your Streamlit app up and running with PropelAuth is quick and easy. Check out our Streamlit guide here or sign up for PropelAuth here.