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
795 stars 200 forks source link

Redirect URI not configurable in code #696

Closed BrianLesko closed 4 months ago

BrianLesko commented 5 months ago

How do you specify the redirect URI, after correctly setting it in Azure online under Authentication and Mobile and Desktop Applications?

Here is the code:

from msal import PublicClientApplication
from clientid import ID
from clientid import tenantid

client_id = ID
authority = f'https://login.microsoftonline.com/{tenantid}'
redirect_uri = 'http://localhost:8501'
app = PublicClientApplication(client_id, authority=authority)

# Acquire token
result = app.acquire_token_interactive(scopes=['User.Read'])
if not result:
    result = app.acquire_token_interactive(['User.Read', 'email'])

# Extract email address from claims
if 'id_token_claims' in result:
    email = result['id_token_claims'].get('email')
    print(f"User's email address: {email}")
### When redirect_uri is added as an arg to acquire_token_interactive there is this error:
TypeError: msal.oauth2cli.oidc.Client.obtain_token_by_browser() got multiple values for keyword argument 'redirect_uri'
### When added to PublicClientApplication an error thrown that it does not take redirect_uri
rayluo commented 4 months ago

How do you specify the redirect URI, after correctly setting it in Azure online under Authentication and Mobile and Desktop Applications? ... When redirect_uri is added as an arg to acquire_token_interactive there is this error:

You don't. Our doc does NOT mention redirect_uri parameter, because there is none. Instead, you can find the port parameter there, whose description hints that you do not have to specify a port at all. In Microsoft Entra ID, you do not need to specify a port for localhost.