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
756 stars 191 forks source link

Error with code=flow["device_code"] #561

Closed AncestorComposition closed 1 year ago

AncestorComposition commented 1 year ago

Describe the bug The sample application returns an error with code=flow["device_code" on line 1973 of application.py in acquire_token_by_device_flow

To Reproduce Steps to reproduce the behavior:

  1. Follow the directions at https://learn.microsoft.com/en-us/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python&tabs=windows

Expected behavior Application should run without errors

What you see instead The sample application returns an error with code=flow["device_code" on line 1973 of application.py in acquire_token_by_device_flow

The MSAL Python version you are using Paste the output of this 1.22.0

rayluo commented 1 year ago

To Reproduce Steps to reproduce the behavior: Follow the directions at https://learn.microsoft.com/en-us/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python&tabs=windows

That link alone is not enough for us to reproduce your issue. In fact, we tested those steps before we published that doc.

Would you mind sharing your setting i.e. the .env file (except the CLIENT_SECRET)? Also, I believe you modified the sample. What changes did you make?

AncestorComposition commented 1 year ago

Hello,

The .env file has just three lines that are not comments (I omitted the actual CLIENT_ID, CLIENT_SECRET, and tenant ID): CLIENT_ID=[ID of the application registered in the Azure Portal] CLIENT_SECRET=[client secret of the application] AUTHORITY=https://login.microsoftonline.com/[tenant ID for my company]

The only other change I made to the sample was to change the REDIRECT_PATH in app_config.py to match the redirect URI which is in Azure Portal for the registered application.

Thank you for your help.

AncestorComposition commented 1 year ago

Here is the full traceback: image

AncestorComposition commented 1 year ago

I resolved the problem. The problem was due to the fact that the callback URI was http://localhost, creating a clash between @app.route(app_config.REDIRECT_PATH) and @app.route("/")