{"id":408,"library":"msal-extensions","title":"Microsoft Authentication Library Extensions","description":"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.","status":"active","version":"1.3.1","language":"python","source_language":"en","source_url":"https://github.com/AzureAD/microsoft-authentication-extensions-for-python","tags":["authentication","MSAL","token cache","persistence","cross-platform"],"install":[{"cmd":"pip install msal-extensions","lang":"bash","label":"Install msal-extensions"}],"dependencies":[{"reason":"Required for authentication functionality","package":"msal"}],"imports":[{"note":"Ensure correct import path to access FilePersistence class.","symbol":"FilePersistence","correct":"from msal_extensions.persistence import FilePersistence"}],"quickstart":{"code":"import os\nfrom msal import ConfidentialClientApplication\nfrom msal_extensions.persistence import FilePersistence\n\n# Set up the persistence layer\ncache = FilePersistence('my_cache.bin')\n\n# Initialize the MSAL application\napp = ConfidentialClientApplication(\n    client_id=os.environ.get('CLIENT_ID'),\n    client_credential=os.environ.get('CLIENT_SECRET'),\n    authority='https://login.microsoftonline.com/your_tenant_id',\n    token_cache=cache\n)\n\n# Acquire a token\nresult = app.acquire_token_for_client(scopes=['https://graph.microsoft.com/.default'])\n\nif 'access_token' in result:\n    print('Access token acquired successfully.')\nelse:\n    print('Failed to acquire access token.')","lang":"python","description":"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."},"warnings":[{"fix":"Install or update the 'msal' package using 'pip install msal'.","message":"Ensure that the 'msal' package is installed and up-to-date to avoid compatibility issues.","severity":"breaking","affected_versions":"all"},{"fix":"Set the 'CLIENT_ID' and 'CLIENT_SECRET' environment variables with appropriate values.","message":"The 'CLIENT_ID' and 'CLIENT_SECRET' environment variables must be set for the script to function correctly.","severity":"gotcha","affected_versions":"all"},{"fix":"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.","message":"The MSAL configuration failed due to 'ValueError: AADSTS90002: Tenant 'your_tenant_id' not found'. This indicates that the tenant ID or tenant name specified in the authority URL is incorrect or does not exist. Double-check your tenant ID or tenant name.","severity":"breaking","affected_versions":"all"},{"fix":"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.","message":"The tenant ID provided in the authority URL (e.g., 'your_tenant_id') is invalid or a placeholder was used. Ensure the authority URL contains a valid tenant ID or tenant name.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:38:33.528Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"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.","cause":"This error occurs in Python 3.12 and later because the `distutils` package, which `msal-extensions` (or its dependency `azure-identity`) historically used for version parsing, was removed from the standard library in Python 3.12.","error":"ModuleNotFoundError: No module named 'distutils'"},{"fix":"Install the library using pip: `pip install msal-extensions`.","cause":"This error indicates that the `msal-extensions` library has not been installed in your Python environment or is not accessible in the current Python path.","error":"ModuleNotFoundError: No module named 'msal-extensions'"},{"fix":"Recompile or reinstall the module for the current Node.js version. Navigate to your project directory and run `npm rebuild` or `npm install`.","cause":"This error typically occurs with `@azure/msal-node-extensions` when the Node.js version used to install the package (which often compiles native binaries like `dpapi.node` via `node-gyp`) differs from the Node.js version used to run the application.","error":"Error: The module '...dpapi.node' was compiled against a different Node.js version using NODE_MODULE_VERSION XX. This version of Node.js requires NODE_MODULE_VERSION YY. Please try re-compiling or re-installing the module...."},{"fix":"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.","cause":"This issue arises when attempting to import `@azure/msal-node-extensions` into an ES Module (ESM) environment in Node.js, because `msal-node-extensions` internally relies on `keytar`, which is a CommonJS module. Direct named imports from CommonJS modules are not always fully supported in ESM.","error":"SyntaxError: Named export 'deletePassword' not found. The requested module 'keytar' is a CommonJS module, which may not support all module.exports as named exports."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.26,"mem_mb":9.4,"disk_size":"37.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":9.4,"disk_size":"38M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.32,"mem_mb":9.8,"disk_size":"40.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.27,"mem_mb":9.8,"disk_size":"41M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.28,"mem_mb":9.6,"disk_size":"31.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.27,"mem_mb":9.6,"disk_size":"32M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.26,"mem_mb":9.6,"disk_size":"31.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.26,"mem_mb":9.6,"disk_size":"32M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":9.2,"disk_size":"37.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":9.2,"disk_size":"38M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}