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.
pip install msal-extensionsVerified import paths — ran on the pinned version, not inferred.
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.
Install or update the 'msal' package using 'pip install msal'.
Set the 'CLIENT_ID' and 'CLIENT_SECRET' environment variables with appropriate values.
Ensure that the tenant ID or tenant name used in the MSAL authority URL (e.g., in `ConfidentialClientApplication` or `PublicClientApplication`) is correct and corresponds to an existing Azure AD tenant. This value is often provided via an environment variable or configuration file.
Provide a valid tenant ID or tenant name in the 'authority' URL when initializing the 'ConfidentialClientApplication'. Replace placeholders like 'your_tenant_id' with an actual tenant ID or tenant name.
Upgrade `msal-extensions` to a version that supports Python 3.12+ (typically 1.0.0 or higher for direct `msal-extensions` usage, or ensure your `azure-identity` dependency is updated to a compatible version like 1.10.0 or newer if `msal-extensions` is a transitive dependency). You might also need to explicitly install a backport of `distutils` if an upgrade is not immediately possible, but updating is the recommended approach.
Install the library using pip: `pip install msal-extensions`.
Recompile or reinstall the module for the current Node.js version. Navigate to your project directory and run `npm rebuild` or `npm install`.
Instead of direct named imports, import the CommonJS module's default export and destructure the required members. For example, change `import { setPassword, getPassword, deletePassword } from 'keytar';` to `import pkg from 'keytar'; const { setPassword, getPassword, deletePassword } = pkg;`. Alternatively, if possible, ensure your Node.js project is configured to run as a CommonJS module.