Skip to main content

yet another msal Single-Sign-On module of streamlit applications also for ConfidentialClientApplication by checking required App roles of signed-in users in the enterprise setup, and support obo flow

Project description

Streamlit-MSAL-2: Yet Another MSAL for Streamlit

Yet another msal Single-Sign-On module of streamlit applications also for ConfidentialClientApplication by checking required App roles of signed-in users in the enterprise setup, and support obo flow.

ci cd pylint PyPI - Python Version PyPI PyPI - Downloads Release GitHub Code style: black

This is a workaround of streamlit to use msal authentication process in an enterprise environment for ConfidentialClientApplication.

How to install and use

  • run pip install
pip install streamlit-msal-2
  • integrate the package in your streamlit code
import streamlit as st
from streamlit_msal_2 import init_auth


st.title("Streamlit MSAL Example")

client_id = "your_client_id"
tenant_id = "your_tenant_id"
user_roles = {
    "ExampleApp.Admin": "ExampleApp.Admin",
    "ExampleApp.User": "ExampleApp.User",
}

init_auth(user_roles, tenant_id, client_id)

st.write(f"Welcome, {st.session_state.username}")

The user sign information is stored in st.session_state.auth_data, the user name is stored in st.session_state.username, and the user roles are stored in st.session_state.roles.

OBO Process

The obo token generation process can be triggered in init_auth, additional arguments need to be provided. The obo token generation process stores the information in st.session_state.obo_info and st.session_state.obo_token.

import streamlit as st
from streamlit_msal_2 import init_auth, refresh_obo_token


st.title("Streamlit MSAL Example")

client_id = "your_client_id"
tenant_id = "your_tenant_id"
user_roles = {
    "ExampleApp.Admin": "ExampleApp.Admin",
    "ExampleApp.User": "ExampleApp.User",
}

client_secret = "your_client_secret"
downstream_scope = "your downstream API scope to be called on-behalf-of user"

init_auth(user_roles, tenant_id, client_id,
  init_obo_process=True, client_secret=client_secret, downstream_scope=downstream_scope)

st.write(f"Welcome, {st.session_state.username}")

st.write(f"token for downstream API call {st.session_state.obo_token}")

# after a long time your token expires
refresh_obo_token(tenant_id, client_id, downstream_scope)

How it works?

  • this package is using streamlit-msal in the background for the authentication.
    • however, streamlit-msal does not specially integrate msal ConfidentialClientApplication, while this is usually mandatorily required by enterprise use cases
  • to simplify enterprise use cases, this package adds some additional role checking after streamlit-msal sign in
    • these required roles can be directly configured in the Microsoft Azure App registration.
    • by assigning user roles in App registration enterprise configuration, the authentication process can automatically check the signed in user's App roles, if it fulfills the predefined user roles, users can go further in streamlit

More to see documentation site.

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_msal_2-0.2.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

streamlit_msal_2-0.2.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_msal_2-0.2.1.tar.gz.

File metadata

  • Download URL: streamlit_msal_2-0.2.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for streamlit_msal_2-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9eda2ba4225d8832b092a71f30500436c2d77c4b79b4f62047217f2ff65e3658
MD5 6a1f13bf1f742c3265e03aed5c514f50
BLAKE2b-256 7bd33b32bb3a20af2931037edf4ac376e35c84025e1d9d1e3ef1a218e223f433

See more details on using hashes here.

File details

Details for the file streamlit_msal_2-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_msal_2-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbb90a3c0d705c841ff1c38f4352a9fc7436f584e23bf7bfceb44159bde74556
MD5 98fb17767d265df976b655265f3474dc
BLAKE2b-256 ee994b74f04706fb8c3d4ffa15c5e872ad8901543272a20130524f08ebfb4b2a

See more details on using hashes here.

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