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.
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.
Metadata
Release files for streamlit-msal-2 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_msal_2-0.2.1.tar.gz | 6.8 kB | Without provenance | Details for streamlit_msal_2-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_msal_2-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for streamlit_msal_2-0.2.1-py3-none-any.whl |
Total release size: 13.9 kB
Release files / streamlit_msal_2-0.2.1.tar.gz
| Download URL | streamlit_msal_2-0.2.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9eda2ba4225d8832b092a71f30500436c2d77c4b79b4f62047217f2ff65e3658
|
|
BLAKE2b-256 checksum How to use checksums |
7bd33b32bb3a20af2931037edf4ac376e35c84025e1d9d1e3ef1a218e223f433
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / streamlit_msal_2-0.2.1-py3-none-any.whl
| Download URL | streamlit_msal_2-0.2.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dbb90a3c0d705c841ff1c38f4352a9fc7436f584e23bf7bfceb44159bde74556
|
|
BLAKE2b-256 checksum How to use checksums |
ee994b74f04706fb8c3d4ffa15c5e872ad8901543272a20130524f08ebfb4b2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for streamlit-msal-2 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.