Microsoft Authentication Library Extensions
MSAL EX provides a persistence API for saving data on disk, encrypted on Windows, macOS, and Linux, with concurrent data access coordinated by a file lock mechanism. Current version: 1.3.1, released on March 14, 2025. Release cadence: approximately quarterly.
Warnings
- breaking Ensure that the 'msal' package is installed and up-to-date to avoid compatibility issues.
- gotcha The 'CLIENT_ID' and 'CLIENT_SECRET' environment variables must be set for the script to function correctly.
Install
-
pip install msal-extensions
Imports
- FilePersistence
from msal_extensions.persistence import FilePersistence
Quickstart
import os
from msal import ConfidentialClientApplication
from msal_extensions.persistence import FilePersistence
# Set up the persistence layer
cache = FilePersistence('my_cache.bin')
# Initialize the MSAL application
app = ConfidentialClientApplication(
client_id=os.environ.get('CLIENT_ID'),
client_credential=os.environ.get('CLIENT_SECRET'),
authority='https://login.microsoftonline.com/your_tenant_id',
token_cache=cache
)
# Acquire a token
result = app.acquire_token_for_client(scopes=['https://graph.microsoft.com/.default'])
if 'access_token' in result:
print('Access token acquired successfully.')
else:
print('Failed to acquire access token.')