Microsoft Authentication Library (MSAL) for Python
The Microsoft Authentication Library (MSAL) for Python enables your app to access the Microsoft Cloud by supporting authentication with Microsoft Azure Active Directory (AAD) and Microsoft Accounts (MSA) using OAuth2 and OpenID Connect. Current version is 1.35.1, with regular updates addressing bugs and feature enhancements.
Warnings
- breaking Support for the Resource Owner Password Credentials (ROPC) flow is deprecated.
- gotcha Ensure environment variable names are correctly set (case-sensitive).
Install
-
pip install msal
Imports
- ConfidentialClientApplication
from msal import ConfidentialClientApplication
Quickstart
import os
from msal import ConfidentialClientApplication
client_id = os.environ.get('AZURE_CLIENT_ID', '')
client_secret = os.environ.get('AZURE_CLIENT_SECRET', '')
authority = 'https://login.microsoftonline.com/your_tenant_id'
app = ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret)
token_response = app.acquire_token_for_client(scopes=['https://graph.microsoft.com/.default'])
print(token_response)