Skip to main content

msal-bearer

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

import requests
import httpx
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 3: 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 uv 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).

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.5.2.tar.gz (6.5 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.5.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msal_bearer-1.5.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.3 CPython/3.13.7 Darwin/25.6.0

File hashes

Hashes for msal_bearer-1.5.2.tar.gz
Algorithm Hash digest
SHA256 1ac2bfa7067b6386137c1b1e210a8ab6cbb64143980fb5ff54223fce7b2cd448
MD5 f38a96ecd53e0408359c35ec253307a7
BLAKE2b-256 ef693e43c49bac97e3d26e5b4ee431ce01fd8a2c18506557ad2b60b682278eed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msal_bearer-1.5.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.3 CPython/3.13.7 Darwin/25.6.0

File hashes

Hashes for msal_bearer-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5a7833f8d632df0aa850a266d9df1356fd1438684e73237c884389a0edd06521
MD5 bc1ded7b2efafbae744d16175ef2afc3
BLAKE2b-256 a23ed93cf1881457ed501338a86d8853c848cd9f9b9f5d761e818eca9f4321bd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.5.2 This release

2 files

1.5.1

2 files

1.5.0

2 files

1.4.5

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 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