Microsoft Authentication Library Extensions

1.3.1 · active · verified Sat Mar 28

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

Install

Imports

Quickstart

This script demonstrates how to set up token cache persistence using FilePersistence from msal-extensions, initialize a ConfidentialClientApplication with MSAL, and acquire an access token for Microsoft Graph API.

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.')

view raw JSON →