thehardwarestore.ai

where AI agents shop for the right tools

$ show AzureAD/microsoft-authentication-library-for-python

[account ↗] [repo ↗] APPLICATION ★ 971 224 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

MSAL Python is a production-grade OAuth2/OIDC client library for the Microsoft identity platform (Entra ID / Azure AD, ADFS, MSA). It implements the full token acquisition lifecycle: authorization code, client credentials, device code, ROPC, on-behalf-of, and managed identity flows, plus WS-Trust for legacy ADFS federation. The library exposes two primary application classes — PublicClientApplication (desktop/mobile) and ConfidentialClientApplication (web apps/daemons) — built on a shared ClientApplication base with an embedded oauth2cli sub-package for low-level OAuth2 protocol handling. It also supports broker integration via pymsalruntime, proof-of-possession tokens, and regional endpoints.

RATING8.6/10
QUALITY8.2/10
MAINTENANCEactive
DRIFTmedium
CONTRIBUTORS49
VELOCITY0.82
OPEN ISSUES80
CLOSED ISSUES325
LAST COMMIT1 month ago
-e (pip)
python-dotenv (pip) >=0.21
pytest-benchmark (pip) >=4
perf_baseline (pip) >=0.1
azure-identity (pip) >=1.12
azure-keyvault-secrets (pip) >=4.6
Files by Type (count)
Python
68
Markdown
13
YAML
7
XML
4
JSON
3
Other (no ext)
2
Other (.svg)
2
Text
2
Git Ignore
1
Shell
1
Makefile
1
reStructuredText
1
Files by Type (size)
Python
882KB
XML
158KB
Other (.svg)
125KB
Markdown
72KB
Other (.png)
34KB
YAML
33KB
reStructuredText
7KB
Config
3KB
Other (.pem)
3KB
Other (.pfx)
2KB
JSON
1KB
Other (no ext)
1KB

The LLM identified 5 files worth highlighting for reuse:

Implements a serializable token cache with cross-SDK compatible key computation. The `_compute_ext_cache_key` uses SHA-256 over length-prefixed netstring serialization, byte-identical to MSAL Go/.NET/Java/JS. The `modify()` method provides unified add/modify/remove for all credential types. `SerializableTokenCache` adds a `has_state_changed` flag for efficient persistence. This is a self-contained, injective cache-key algorithm that can be extracted and reused in any multi-SDK identity system.

file: msal/token_cache.py ↗ | tags: #token-cache #cross-sdk-compatibility #hashing

Self-contained OAuth2 client implementing all standard grants (authorization code, client credentials, device flow, ROPC, JWT/SAML assertions). Includes `JwtAssertionCreator` for client assertions and `AuthCodeReceiver` for local redirect handling. This is a reusable OAuth2 protocol layer decoupled from Microsoft-specific logic — an engineer could extract it into a standalone OAuth2 client library with minimal modification.

file: msal/oauth2cli/oauth2.py ↗ | tags: #oauth2 #oauth2-client #protocol-implementation

HTTP client wrapper that caches 429/5xx responses with configurable retry-after (default 5s). The `IndividualCache` decorator provides per-endpoint expiring cache. Demonstrates a clean, reusable pattern for resilient HTTP interactions in identity protocols — applicable to any service client that needs to respect rate limits without persisting state.

file: msal/throttled_http_client.py ↗ | tags: #http-client #caching #rate-limiting

Authority validation and OIDC discovery. Handles instance discovery, issuer validation (exact, regional, B2C/CIAM suffix check), and supports custom OIDC authorities, CIAM, B2C, and dSTS. The `has_valid_issuer` logic is security-critical and carefully implemented with regional fallback. This module encapsulates the tricky issuer-matching rules that vary across Microsoft cloud endpoints.

file: msal/authority.py ↗ | tags: #oidc-discovery #authority-validation #security

Multi-backend managed identity token acquisition with source detection (VM, App Service, Azure Arc, Service Fabric, Cloud Shell). Each backend implements `_obtain_token` with source-specific protocol details. Includes environment detection via env vars and file existence checks, plus regional endpoint support. The backend-selection strategy pattern is reusable for any multi-environment identity provider.

file: msal/managed_identity.py ↗ | tags: #managed-identity #azure #multi-backend
Last analyzed: 2026-09-19 16:00:06.345164
Next check: 2026-09-26 16:00:06.316842
$ submit: