Azure-Samples / Azure-Samples/ms-identity-python-daemon
Samples: incorrect/misleading cached token lookup using `account=None`
- Dominant language
- PowerShell
- Stars
- 62
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
In the `1-Call-MsGraph-WithSecret` sample, the comments explain that calling `app.acquire_token_silent` will look up a token from cache ([source](https://github.com/Azure-Samples/ms-identity-python-daemon/blob/bbc488c40cc548dbfeef7c2178e8ee1b46abf8e3/1-Call-MsGraph-WithSecret/confidential_client_secret_sample.py#L53-L56)).
```python
# Firstly, looks up a token from cache
# Since we are looking for token for the current app, NOT for an end user,
# notice we give account parameter as None.
result = app.acquire_token_silent(config["scope"], account=None)
```
However, the current behavior of the acquire_token_silent function will immediately return None if the account parameter is provided as None as given in the sample ([source](https://github.com/AzureAD/microsoft-authentication-library-for-python/blob/c1ead1caece73b81f7cb168ca22f8741504ec5bd/msal/application.py#L1284-L1285)).
```python
def acquire_token_silent(
self,
scopes, # type: List[str]
account, # type: Optional[Account]
...
if not account:
return None # A backward-compatible NO-OP to drop the account=None usage
```
Can the sample be updated to show how to properly retrieve a cached token?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.