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
757 stars 192 forks source link

Cannot put client id into scopes, therefore cannot get access_token for Azure B2C #505

Closed anch2150 closed 1 year ago

anch2150 commented 1 year ago

According to Azure B2C documentation, to get an access_token, client id must be added to scopes, i.e. scopes=['openid', 'offline_access', '<CLIENT_ID>'].

The OpenID Connect standard specifies several special scope values. The following scopes represent the permission to access the user's profile:

  • openid - Requests an ID token.
  • offline_access - Requests a refresh token using Auth Code flows.
  • 00000000-0000-0000-0000-000000000000 - Using the client ID as the scope indicates that your app needs an access token that can be used against your own service or web API, represented by the same client ID.

However, _decorate_scope will replace client id with ['openid', 'profile', 'offline_access'], which does not generate access_token.

https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/545e856124985da4758530ab811d2c137fa8e333/msal/application.py#L591

rayluo commented 1 year ago

So, did you end up seeing this exception?

What if you use scopes=['<YOUR_CLIENT_ID>'] alone?

anch2150 commented 1 year ago

Here is my experiments:

rayluo commented 1 year ago

@anch2150 , thanks again for bringing this to our attention. We worked out a PR for it. You may want to test it out, because the implementation is slightly different than the last bullet point that you mentioned above. Hope we can hear back from you within a day or two, before we proceed to merge in that PR.