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"]

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

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-Auth-Request-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.3.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.4.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msal_bearer-1.4.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Darwin/25.0.0

File hashes

Hashes for msal_bearer-1.4.3.tar.gz
Algorithm Hash digest
SHA256 1d0a7fc4d46315c0264046fc23d3ad7734887b2b54d7460fba462a2aea816a50
MD5 a4f79d1b5b3ac9acdf7fec9f2f3627ab
BLAKE2b-256 091b8d521adeaba971b1e6fb68d5e37e068805a1018932dd3417a7bb329816e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msal_bearer-1.4.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Darwin/25.0.0

File hashes

Hashes for msal_bearer-1.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0493cd6bf63654f9692ace2d739871028b3aff7c5cd39d1e7605d289b2d92f
MD5 4f24f73cc3611f4511be114e7a4592a0
BLAKE2b-256 cad114374f1aa4adc18096dbf396d54525fbaf75a15be665fba72534eeb599c7

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