Skip to main content

Python package to get auth token for a msal client application using msal, msal-extensions and azure-identity.

Project description

msal-bearer SNYK dependency check

Python package to get authorization token interactively for a msal application.
For public client application using user impersonation it also handles local cache and refreshing the token.

Usage 1: Public client application user impersonation

from msal_bearer import BearerAuth

tenant_id = "YOUR_TENANT_ID"
client_id = "YOUR_CLIENT_ID"
scope = ["YOUR_SCOPE"]

auth = BearerAuth.get_auth(
    tenantID=tenant_id,
    clientID=client_id,
    scopes=scope
)

# Supports requests
response = requests.get("https://www.example.com/", auth=auth)

# and httpx
client = httpx.Client()
response = client.get("https://www.example.com/", auth=auth)

Usage 2: Confidential client with secret

from msal_bearer import Authenticator

tenant_id = "YOUR_TENANT_ID"
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
scope = ["YOUR_SCOPE"]

a = Authenticator(
    tenant_id=tenant_id
    client_id=client_id,
    client_secret=client_secret,
)
token = a.get_token(scopes=scope)

Usage 2: Confidential client with user_assertion for OBO authentication on streamlit

from msal_bearer import Authenticator

tenant_id = "YOUR_TENANT_ID"
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
scope = ["YOUR_SCOPE"]

user_assertion = st.context.headers["X-Forwarded-Access-Token"]

a = Authenticator(
    tenant_id=tenant_id
    client_id=client_id,
    client_secret=client_secret,
    user_assertion=user_assertion,
)
token = a.get_token(scopes=scope)

Installing

Clone and install using poetry or install from pypi using pip.

pip install msal_bearer

Alternatives

Other similar packages include https://pypi.org/project/msal-requests-auth/ (for confidential client applications) and https://pypi.org/project/msal-interactive-token-acquirer/ (no caching implemented).

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

msal_bearer-1.4.4.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msal_bearer-1.4.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file msal_bearer-1.4.4.tar.gz.

File metadata

  • Download URL: msal_bearer-1.4.4.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for msal_bearer-1.4.4.tar.gz
Algorithm Hash digest
SHA256 e71c99ec2088f20ea700fe6e8588f8e47a343b7399f1639954513a5c587a03ad
MD5 ade36e3f691dde15b8768662791a5dc4
BLAKE2b-256 3bba86189d8507fae2b2fbd77037e66fc4d7b770b14c55fc00f4906673d5e508

See more details on using hashes here.

File details

Details for the file msal_bearer-1.4.4-py3-none-any.whl.

File metadata

  • Download URL: msal_bearer-1.4.4-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for msal_bearer-1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2f2027d129fd260d3e78d24d77f53dfda762ad8dd6c1156d1ca437d995412bf8
MD5 a2e287daaa3eb5b8ee56c2859348da30
BLAKE2b-256 ab18d59536df99ec2a8f1252e5532a7e8738f42cdd9bfc347f75f588c03452b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page