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.1.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.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msal_bearer-1.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e835c849e41bfaef8d37fda3b55028d5f736b446fd5ad4b73d5993dcf941c7a5
MD5 f12c3203e96acdeedfb79d427018382f
BLAKE2b-256 1efb0a87b6937c4ebfe5012e89bc68e2a946bf6a6343b6bb76b74403bb23c286

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msal_bearer-1.5.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03c2d12920fe84e6719b5391ce2b5de93089d21435265deb7e790e93cd758517
MD5 31e40ecb18a82f529170e60e9537655b
BLAKE2b-256 241ad193efdf2185114e85f296c46b469d95d1af4d5b2ba3021f54ea620068df

See more details on using hashes here.

Release history Release notifications | RSS feed

1.5.2

2 files

This release

1.5.1 This release

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