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

[Bug] remove_account() function fails with "TypeError: string indices must be integers, not 'str'" #643

Closed dmulder closed 6 months ago

dmulder commented 6 months ago

Describe the bug Using the latest msal (v1.26.0) calling remove_account() on a PublicClientApplication for a user which is in the cache causes the error "TypeError: string indices must be integers, not 'str'".

To Reproduce Steps to reproduce the behavior:

import msal

app = msal.PublicClientApplication(app_id, authority=authority_url)
token = app.acquire_token_by_username_password(username, password, scopes)
if 'access_token' in token:
    app.remove_account(username)

app_id, authority_url, username, password, and scopes need to be defined. This produces the following output:

Traceback (most recent call last):
  File "<homedir>/test.py", line 11, in <module>
    app.remove_account(username)
  File "<homedir>/.msal_testbed/lib64/python3.11/site-packages/msal/application.py", line 1126, in remove_account
    self._forget_me(account)
  File "<homedir>/.msal_testbed/lib64/python3.11/site-packages/msal/application.py", line 1161, in _forget_me
    self._sign_out(home_account)
  File "<homedir>/.msal_testbed/lib64/python3.11/site-packages/msal/application.py", line 1136, in _sign_out
    "environment": home_account["environment"],
                   ~~~~~~~~~~~~^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

Expected behavior User should be removed from cache.

What you see instead User is still in the cache and an error is displayed.

The MSAL Python version you are using 1.26.0

dmulder commented 6 months ago

I just looked at the msal code and realized this function accepts an account object, not a username. This could possibly be addressed in the documentation instead, so that the python docs are clear about what object should be passed here.

rayluo commented 6 months ago

I just looked at the msal code and realized this function accepts an account object, not a username. This could possibly be addressed in the documentation instead, so that the python docs are clear about what object should be passed here.

Sorry to hear your suboptimal experience. We do provide API documentation whose link is available from the README of this repo.

In particular, although the doc for remove_account() api does not currently have much detail, we were hoping the function name containing "account" would be a hint.