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

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

未关闭
#30 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PowerShell
星标
62
派生
27
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。