Azure-Samples / Azure-Samples/ms-identity-python-daemon

Samples: incorrect/misleading cached token lookup using `account=None`

Aperta
#30 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
PowerShell
Stelle
62
Fork
27
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.