{"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,"search_vec":"'1.3.1':34 '14':38 '2025':39 'access':25 'api':10 'approxim':42 'authent':2,44 'cach':47 'cadenc':41 'concurr':23 'coordin':26 'cross':50 'cross-platform':49 'current':32 'data':13,24 'disk':15 'encrypt':16 'ex':6 'extens':4 'file':29 'librari':3 'linux':21 'lock':30 'maco':19 'march':37 'mechan':31 'microsoft':1 'msal':5,45 'persist':9,48 'platform':51 'provid':7 'quarter':43 'releas':35,40 'save':12 'token':46 'version':33 'window':18","created_at":"2026-03-28T11:15:20.989660+00:00","updated_at":"2026-04-16T16:41:12.999991+00:00","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,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"1.3.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/AzureAD/microsoft-authentication-extensions-for-python","docs":null,"changelog":"https://github.com/AzureAD/microsoft-authentication-extensions-for-python/releases","pypi":"https://pypi.org/project/msal-extensions/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","azure"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}