Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
293 stars 138 forks source link

question: localhost vs 127.0.0.1 redirect URI #104

Open pawelofficial opened 1 year ago

pawelofficial commented 1 year ago

hi, this is my first time opening an issue so i apologize in advance for it's quality. Nevertheless i am following https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-authentication-sample-python-web-app tutorial and my redirect URI didn't match in step 5.4, exact message from flask: GET /getAToken.?error=redirect_uri_mismatch&error_description=AADB2C90006:+The+redirect+URI+'http://127.0.0.1:5000/getAToken'+provided+in+the+request+is+not+registered+for+the+client+id+'xxx-xx-xx-xx-xx'.%0d%0aCorrelation+ID:+xxx-xxx-xxx-xx-xxx%0d%0aTimestamp:+2023-05-03+10:03:02Z%0d%0a&state=jsaKCDnFuqMGzkrL

and when i hardcoded the redirect_uri in login route to "http://localhost:5000/getAToken." it worked.

pawelofficial commented 1 year ago

as pointed out 5 years ago here https://stackoverflow.com/questions/41581369/microsoft-application-redirect-uri-allows-localhost-but-not-127-0-0-1 one can change redirect url via manifest on Azure site to allow for http://127.0.0.1 which fixes the issue

rayluo commented 1 year ago

You seemed to be going through the hard route to enable 127.0.0.1 which was not allowed in Azure Portal.

I believe you can try following our README, which references to a Quickstart guide, whose last step tells you to run your flask server with a --host=localhost parameter, that way you would probably not run into this 127.0.0.1 issue at all. Please test and let us know.

Jaya-sys commented 1 year ago

Or you can pass the value in app.run(localhost="locahost") and can give the uri path in the azure directory

rayluo commented 1 year ago

Or you can pass the value in app.run(localhost="locahost") and can give the uri path in the azure directory

Did you mean to say app.run(host="...")? I see no localhost parameter in Flask.run()'s docs.

Regardless, this sample itself does not intend to hardcode for localhost, because we do not want to support localhost-only. If anything, we just want to discourage 127.0.0.1.

pawelofficial commented 1 year ago

i did, sorry

rayluo commented 1 year ago

i did, sorry

That is OK. You are welcome. :-)