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).
Metadata
Release files for msal-bearer 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| msal_bearer-1.6.0.tar.gz | 7.3 kB | Without provenance | Details for msal_bearer-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| msal_bearer-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for msal_bearer-1.6.0-py3-none-any.whl |
Total release size: 15.8 kB
Release files / msal_bearer-1.6.0.tar.gz
| Download URL | msal_bearer-1.6.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6ee1d79e2d41ac7d06fdf90a405c6d0c3bb19c5946218a4c6225d8c05637a0f
|
|
BLAKE2b-256 checksum How to use checksums |
a0652662c0df45d2cf251ec8ceb986c0e53351de7ed99f07579dd016baf17fe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.3 CPython/3.13.7 Darwin/27.2.0
|
Release files / msal_bearer-1.6.0-py3-none-any.whl
| Download URL | msal_bearer-1.6.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a51a5ca7060bbb060d039c48ae82cb7ba09558f839f86d09c49a657867ad49e
|
|
BLAKE2b-256 checksum How to use checksums |
8a5acadf974486fbd5289cf3230df97abf3b014c14c4fcb4db06986378f6a55b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.3 CPython/3.13.7 Darwin/27.2.0
|
Security for msal-bearer 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.