Registry /
azure / microsoft-agents-authentication-msal
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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 58.7MB
glibcpy 3.10–3.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.")
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.