Skip to main content

OpenID Connect (OIDC) authentication component for Streamlit

About

This Streamlit component enables client-side authentication using Azure AD work and school accounts (AAD), Microsoft personal accounts (MSA) and social identity providers like Facebook, Google, LinkedIn, Microsoft accounts, etc. through Azure AD B2C service. The component is achieving this by applying the Microsoft MSAL JS Library inside of a React project. Since the component is based on MSAL, it can be configured to support any provider that supports the OpenID Connect Authorization Code Flow (PKCE). For more information on MSAL, consult the Github project and its offical documentation.

Usage

Below is a sample Python snippet displaying how to apply the component. Visually, the component gives rise to a single button in the Streamlit Dashboard with a text that depends on whether an active login session exists. The auth and cache parameters are entirely equivalent to the properties mentioned in the Github documentation. The login_request and logout_request parameters are covered here.

import streamlit as st
from msal_streamlit_authentication import msal_authentication


login_token = msal_authentication(
    auth={
        "clientId": "aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee",
        "authority": "https://login.microsoftonline.com/aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee",
        "redirectUri": "/",
        "postLogoutRedirectUri": "/"
    }, # Corresponds to the 'auth' configuration for an MSAL Instance
    cache={
        "cacheLocation": "sessionStorage",
        "storeAuthStateInCookie": False
    }, # Corresponds to the 'cache' configuration for an MSAL Instance
    login_request={
        "scopes": ["aaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee/.default"]
    }, # Optional
    logout_request={}, # Optional
    login_button_text="Login", # Optional, defaults to "Login"
    logout_button_text="Logout", # Optional, defaults to "Logout"
    class_name="css_button_class_selector", # Optional, defaults to None. Corresponds to HTML class.
    html_id="html_id_for_button", # Optional, defaults to None. Corresponds to HTML id.
    key=1 # Optional if only a single instance is needed
)
st.write("Recevied login token:", login_token)

A minimal sample project using the library can be found here. Note that it is Dockerized.

The component currently expects for the user to go through a popup based login flow. Further flows may be supported at a later time. As discussed here, the protocolMode parameter in auth can be used to configure OIDC providers that differ from Azure AD.

Inspiration

Inspired by official Streamlit template, this tutorial (Github) and the official Streamlit NPM component-lib.

Release files for msal-streamlit-authentication-options 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for msal-streamlit-authentication-options 1.0.9
File Size Uploaded
msal_streamlit_authentication_options-1.0.9.tar.gz 180.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for msal-streamlit-authentication-options 1.0.9
File Interpreter ABI Platform
msal_streamlit_authentication_options-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 361.8 kB

Release files / msal_streamlit_authentication_options-1.0.9.tar.gz

Download URL msal_streamlit_authentication_options-1.0.9.tar.gz
Size 180.3 kB
Tags Source
SHA-256 checksum
How to use checksums
078505864bd438f666ee071851c3f2cd3e09d60bd6ad1fda21a0bd298a34a01c
BLAKE2b-256 checksum
How to use checksums
9a7032dd53d1d5178d313a45706ff1adcb82791191315bdd9a58b43b7ffbcaf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / msal_streamlit_authentication_options-1.0.9-py3-none-any.whl

Download URL msal_streamlit_authentication_options-1.0.9-py3-none-any.whl
Size 181.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e17757f588ea6da775bc9728154a004b00d82cebade83ecbd3bbe7b7ddc58a3
BLAKE2b-256 checksum
How to use checksums
ca14a3c015ec2efb16944be5863231f52d4675b3830b32a2f5771d96f75292a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page