AzureAD / microsoft-authentication-library-for-python

Microsoft Authentication Library (MSAL) for Python makes it easy to authenticate to Microsoft Entra ID. General docs are available here https://learn.microsoft.com/entra/msal/python/ Stable APIs are documented here https://msal-python.readthedocs.io. Questions can be asked on www.stackoverflow.com with tag "msal" + "python".
https://stackoverflow.com/questions/tagged/azure-ad-msal+python
Other
788 stars 194 forks source link

Device code login take 60s to complete #408

Closed jiasli closed 2 years ago

jiasli commented 2 years ago

The HTTP cache introduced by #379 makes device code login very slow, as the response is now cached. The retry logic goes to the cache and see 400 is returned.

https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/f97cb7c69d1f5c2eed6c85e28dd828b2434263b4/msal/oauth2cli/oauth2.py#L383-L390

Device code login now can take as long as 60s.

The cache look up behavior can be confirmed by logging the cache query before

https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/27097e66d1844b7862439c551360ce90d3615ab6/msal/individual_cache.py#L263

                if self._mapping[key] is not None:
                    print("hit")

Output:

urllib3.connectionpool: https://login.microsoftonline.com:443 "POST /organizations/oauth2/v2.0/token HTTP/1.1" 400 510
hit
hit
hit
hit
hit

The exclusion rule for device code flow

https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/a1f9ca7cc0cbd4330ea91b729f700de9d275c9d7/msal/throttled_http_client.py#L112

doesn't work because data is not passed to

https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/27097e66d1844b7862439c551360ce90d3615ab6/msal/individual_cache.py#L271-L276