![](/img/trans.png)
[英]Does the Python SDK for CosmosDB not allow for token/credential auth?
[英]Azure Python SDK Credential Refresh
我正在使用azure python sdk
linux
編程方式連接到 azure 服務。
我可以通過az('login')
成功登錄
login found
但是,當我嘗試創建憑據並獲取令牌時,我收到一條錯誤消息,提示我的授權已過期:
creds = DefaultAzureCredential()
token = creds.get_token('https://database.windows.net/.default')
VisuaLStudioCodeCredential.get_token failed: Azure Active Directory error ' (invalid_grant) AADSTS50173: The provided grant has expired due to it being revoked, a fresh auth token is needed. The user might have changed or reset their password. The grant was issued on '2021-11-04T15:21:38,19517642' and the TokensValidFrom date (before which tokens are not valid) for this user is '2022-01-0819:52:17.0000000z'
我該如何刷新這個? 我嘗試使用az('account clear')
,然后使用az('login')
但我得到了相同的結果。 是否有特定於DefaultAzureCredential
的方法來獲取刷新的令牌?
DefaultAzureCredential
class 嘗試以特定順序使用多種方法獲取令牌,VS Code 登錄用戶的優先級高於 Azure CLI 登錄用戶。
當您使用az login
時,您正在使用 Azure CLI 登錄,並且您似乎已經使用其他一些沒有適當權限的憑據登錄到 VS Code,這就是您收到此錯誤的原因。
要解決此問題,您可以通過將exclude_visual_studio_code_credential
設置為true
來排除要考慮的 VS Code 憑據。 所以你的代碼會是這樣的:
creds = DefaultAzureCredential(exclude_visual_studio_code_credential=true)
這樣 DefaultAzureCredential 就不會使用你的 VS Code 憑據來獲取令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.