Skip to main content

Streamlit Authentication library based on MSAL.JS

Project description

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.

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

Built Distribution

File details

Details for the file msal_streamlit_authentication_dentro-1.0.9.tar.gz.

File metadata

File hashes

Hashes for msal_streamlit_authentication_dentro-1.0.9.tar.gz
Algorithm Hash digest
SHA256 e7df025d02ee89541b0e7da3e3eecd8cfdfe2c00f8497a71d8c292ce10db973f
MD5 b6f2cde2d3cdeb5c850772a50889ca53
BLAKE2b-256 2af201898bb3abaad3f1e4174355c4562c4b55c8530e2f78de342f04e14ab830

See more details on using hashes here.

Provenance

File details

Details for the file msal_streamlit_authentication_dentro-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for msal_streamlit_authentication_dentro-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 47ff6b90f32170943631544491a142b762eeb9fd2ab24a1a4f02c1bcf670e78c
MD5 e41f1a49ba889cd17c1e0514d5277f44
BLAKE2b-256 18b3010109d9580528d9b8c98eea6a460af3ea9ac140d5b3e973d1c689e4c646

See more details on using hashes here.

Provenance

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