Microsoft Authentication Library (MSAL) for Python

1.35.1 · active · verified Wed Oct 04

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

Install

Imports

Quickstart

This example demonstrates how to acquire an access token for Azure AD.

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)

view raw JSON →