-
Notifications
You must be signed in to change notification settings - Fork 208
Description
Describe the bug
Using allow_broker with device code flow causes token refreshing to fail: Account with id '(pii)' not found.
To Reproduce
# Opt-in WAM
az config set core.allow_broker=true
# Turn off token encryption so that we can edit it manually later
az config set core.encrypt_token_cache=false
# Log in with device code, but with an account not in WAM, such as domain account [email protected]
az login --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a --use-device-code
# Edit ~/.azure/msal_token_cache.json. Change AccessToken.<key>.expires_on to 0 to make the access token expire
# {
# "AccessToken": {
# "...": {
# ...
# "expires_on": "0",
# Trigger token refreshing
az group listExpected behavior
Token refreshing should succeed.
What you see instead
Account with id '(pii)' not found. Status: Response_Status.Status_AccountNotFound, Error code: 0, Tag: 525678464
Apparently, this is because device code's refresh token is saved to MSAL token cache, not WAM, but during token refreshing, MSAL tries to get access token from WAM.
The MSAL Python version you are using
Latest dev branch: 56256e4
Additional context
I understand there is no point to use device code flow when broker is available, but it's better to make the whole workflow more user-friendly.
If MSAL exposes enable_broker rather than allow_broker (like what it is doing internally):
| self._enable_broker = True |
life will be much easier - simply raise an error if acquire_token_by_device_flow is called on a PublicClientApplication with enable_broker=True.
Such allow_... design makes the logic far more complex - both acquire_token_by_device_flow and acquire_token_silent_with_error need to implement such fallback logic and be consistent with each other. In this issue, acquire_token_by_device_flow falls back to MSAL token cache, but acquire_token_silent_with_error doesn't and still reads from WAM.