Registry / azure / microsoft-agents-authentication-msal

microsoft-agents-authentication-msal

JSON →
library1.0.0pypypiunverified

microsoft-agents-authentication-msal is a Python library providing MSAL-based authentication specifically for Microsoft Agents. It primarily implements the device code flow using MSAL to acquire authentication tokens. Currently at version 0.9.0, it's part of the broader Microsoft Agents framework and follows its release cadence, focusing on integrating with Microsoft services.

pip install microsoft-agents-authentication-msal
INSTALL
IMPORT
SIG · MICROSOFT-AGENTS-A
M
microsoft-agents-authentication-msal
azurepythonv1.0.0
Install
5.9s avg
Import
Disk
57MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 58.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 5.9s · import 0.000s · 58MB
57MB installed
● package 57MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MSALAuthentication
from microsoft_agents.auth.msal import MSALAuthentication
from microsoft_agents.auth.msal import MSALAuthentication

Demonstrates basic authentication using the MSAL Device Code Flow. It initializes `MSALAuthentication` with a client ID and attempts to acquire an access token for the Microsoft Graph default scope. Note that this flow requires user interaction in a web browser.

import os from agents.auth.msal import MSALAuthentication from agents.auth.types import IAuthentication # For demonstration, retrieve client_id from environment variable. # In a real application, you would configure this securely. CLIENT_ID = os.environ.get('MSAL_CLIENT_ID', 'YOUR_MSAL_CLIENT_ID_HERE') if CLIENT_ID == 'YOUR_MSAL_CLIENT_ID_HERE': print("WARNING: Please set the MSAL_CLIENT_ID environment variable or replace 'YOUR_MSAL_CLIENT_ID_HERE' with your actual Azure AD application client ID.") try: # Initialize MSAL authentication using Device Code Flow # This will print a URL and a device code that the user needs to enter in a browser. auth: IAuthentication = MSALAuthentication(client_id=CLIENT_ID) print(f"Attempting to get token with client_id: {CLIENT_ID}...") # Acquire a token for Microsoft Graph default scope # The actual scope might vary depending on the Microsoft Agent's requirements. # Common scopes include "https://graph.microsoft.com/.default" for broad Graph access. # Other scopes like "api://<your-app-id>/.default" might be used for custom APIs. token_response = auth.get_token(scope=["https://graph.microsoft.com/.default"]) print("\nAuthentication successful!") print(f"Access Token (first 20 chars): {token_response.access_token[:20]}...") print(f"Expires On: {token_response.expires_on}") except ValueError as e: print(f"Error during authentication setup: {e}") if "client_id" in str(e): print("Hint: Ensure MSAL_CLIENT_ID is correctly set and not empty.") except Exception as e: print(f"An unexpected error occurred during token acquisition: {e}") print("Please check your network connection, client_id, and ensure you completed the device code flow in the browser.")
Debug
Known issues
gotchaThis library requires Python 3.10 or newer. Installing with older Python versions will lead to dependency resolution errors or runtime issues.
fix
Ensure your Python environment is version 3.10 or higher. Use `python --version` to check.
affects: All versions
breakingThe import path `from microsoft_agents_authentication_msal import MSALAuthentication` is incorrect and will result in a `ModuleNotFoundError`.
fix
Always use `from agents.auth.msal import MSALAuthentication` as the correct import path, matching the internal module structure.
affects: All versions
gotchaThe `MSALAuthentication` class primarily implements the Device Code Flow, which requires user interaction in a web browser.
fix
Be prepared for the application to print a URL and a code. The user must navigate to the URL, enter the code, and complete authentication in their browser. This flow is not suitable for fully automated, headless environments without specific MSAL configuration.
affects: All versions
gotchaA valid Azure AD application Client ID is essential for successful authentication. Using a placeholder or an invalid ID will cause errors.
fix
Register an application in Azure Active Directory (AAD), grant it the necessary API permissions (e.g., Microsoft Graph), and use its assigned Client ID. Ensure the application type supports public client flows for device code.
affects: All versions
Upgrade
Version history
1.0.0latest on PyPI · released May 22, 2026
Audit
Dependencies
microsoft-agents-authenticationrequiredProvides the IAuthentication interface that this library implements.
msalrequiredThe core Microsoft Authentication Library (MSAL) that this package wraps.
Agent activity
29 hits · last 30 days
node
26
OpenAI (training)
1
Resources
microsoft-agents-authentication-msal — pip install microsoft-agents-authentication-msal · libregistry