Skip to main content

Streamlit component for AzureAD ConfidentialClientApplication using Microsoft Authentication Library (MSAL), this is further developed based on original straemlit-msal by WilianZilv

Project description

Streamlit-MSAL-2

cd Code style: black

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

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

How to configure and use?

Configure Azure App Registration

  • go Microsoft Azure portal

  • search App registration, and click into it

  • select an existing App registration, or create a new one if you do not have

    • portal
  • click to copy your tenant id and client id

    • ids
  • add App roles

    • app-roles
  • in Authentication, you have to add single-page application. for local test runs, if using streamlit default port, add http://localhost:8501

Configure Enterprise Application

  • go to Enterprise Application in Overview page

    • overview
  • add your target users, and remember to select the corresponding App roles you just created

    • users-groups

Streamlit Python 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}")

Details check example folder

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.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

streamlit_msal_2-0.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_msal_2-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 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.0.1.tar.gz
Algorithm Hash digest
SHA256 167876fe836cb1fc0d4a93693fa0f959fbfc25e3a913730e11de671ad25e626e
MD5 61a5e9e44bced66aa60ae86481830d05
BLAKE2b-256 8d2a94e8137f88cde78c5311aef8d024f14cdedb1a3cd26b022922e76c77ed17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_msal_2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7e75e436d00b1bceedf469f7af0b9a2c201316b94f8fe7a9ea9d1ad3755d023
MD5 3b5a4e54b8349586e931fbe252e5163c
BLAKE2b-256 899e2d022279ed07d842e7abb785c24c1e788f70fdc72de522ee3a33327ac7f2

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