gpt4 book ai didi

python - 密码更改后 Azure ChainedTokenCredential 失败

转载 作者:行者123 更新时间:2023-12-02 22:51:00 24 4
gpt4 key购买 nike

Azure ChainedTokenCredential修改密码后本地开发失败。我一直在使用ChainedTokenCredential使用 ManagedIdentityCredential 进行几周的身份验证在 Azure 和 DefaultAzureCredential用于我的功能应用程序的本地测试。一切都按计划进行。下面是一个代码示例,该代码示例在 Azure 中一直有效,但在本地却无效。

def get_client():

MSI_credential = ManagedIdentityCredential()
default_credential = DefaultAzureCredential()
credential_chain = ChainedTokenCredential(MSI_credential, default_credential)

storageurl = os.environ["STORAGE_ACCOUNT"]

client = BlobServiceClient(storageurl, credential=credential_chain)
return client

上周我不得不更改密码,从那时起我收到以下错误。

[2021-04-19T15:18:06.931Z] SharedTokenCacheCredential.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-02-08T20:05:01.4240000Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-04-15T15:49:33.0000000Z'.
[2021-04-19T15:18:06.963Z] Trace ID: xxx
[2021-04-19T15:18:06.972Z] Correlation ID: xxx
[2021-04-19T15:18:06.974Z] Timestamp: 2021-04-19 15:17:46Z'
[2021-04-19T15:18:06.977Z] DefaultAzureCredential.get_token failed: SharedTokenCacheCredential raised unexpected error "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-02-08T20:05:01.4240000Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-04-15T15:49:33.0000000Z'.
[2021-04-19T15:18:07.014Z] Trace ID: xxx
[2021-04-19T15:18:07.040Z] Correlation ID:
[2021-04-19T15:18:07.046Z] Timestamp: 2021-04-19 15:17:46Z'"
[2021-04-19T15:18:07.061Z] DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential: 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-02-08T20:05:01.4240000Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-04-15T15:49:33.0000000Z'.
[2021-04-19T15:18:07.094Z] Trace ID: xxx
[2021-04-19T15:18:07.097Z] Correlation xxx
[2021-04-19T15:18:07.108Z] Timestamp: 2021-04-19 15:17:46Z'
[2021-04-19T15:18:07.111Z] ChainedTokenCredential.get_token failed: DefaultAzureCredential raised unexpected error "DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential: 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-02-08T20:05:01.4240000Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-04-15T15:49:33.0000000Z'.
[2021-04-19T15:18:07.147Z] Trace ID: xxx
[2021-04-19T15:18:07.181Z] Correlation ID: xxx
[2021-04-19T15:18:07.195Z] Timestamp: 2021-04-19 15:17:46Z'"
[2021-04-19T15:18:07.201Z] ChainedTokenCredential failed to retrieve a token from the included credentials.
Attempted credentials:
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
DefaultAzureCredential: DefaultAzureCredential failed to retrieve a token from the included credentials.
Attempted credentials:
EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential: 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-02-08T20:05:01.4240000Z' and the TokensValidFrom date (before which tokens are not valid) for this user is '2021-04-15T15:49:33.0000000Z'.
[2021-04-19T15:18:07.241Z] Trace ID: xxx
[2021-04-19T15:18:07.264Z] Correlation ID: xxx
[2021-04-19T15:18:07.303Z] Timestamp: 2021-04-19 15:17:46Z'

我尝试解决该问题的方法:

  1. 登录和退出 VSCode Azure 扩展
  2. 登录和退出 az cli
  3. az account clear
  4. 清除浏览器缓存。
  5. 重新启动 PC 和 VSCode。
  6. 清除 VSCode 缓存
    • C:\Users\<user>\AppData\Roaming\Code\Cache
    • C:\Users\<user>\AppData\Roaming\Code\CacheData

我正在使用 Azure 扩展“附加到 Python 函数”来运行调试器。我不确定如何DefaultAzureCredential正在获取我的凭据。我相信它存储在本地,因为在未登录 Azure 扩展的情况下运行调试器时,我遇到了相同的错误。我以为DefaultAzureCredential会使用我的 Azure 扩展以我的身份登录来进行身份验证,但我不确定。

如有任何帮助,我们将不胜感激!

最佳答案

该问题已通过使用 @Charles Lowell 的解决方案得到解决。由于使用 fzf.exe(模糊查找工具),我无法找到该文件,并且默认情况下它不会在隐藏文件夹中查找。正在删除C:\Users\<user>\AppData\Local\.IdentityService\msal.cache工作了。

我发现的另一种选择是使用 VisualStudioCodeCredential()而不是DefaultAzureCredential() 。这使用 vscode 扩展进行身份验证。我更喜欢这种方法,但并非所有开发人员都使用 VSCode。我很高兴得到DefaultAzureCredential工作。

def get_client():

MSI_credential = ManagedIdentityCredential()
vscode_credential = VisualStudioCodeCredential()
credential_chain = ChainedTokenCredential(MSI_credential, vscode_credential)

有关DefaultAzureCredential()的更多信息可以查到here .

谢谢大家!

关于python - 密码更改后 Azure ChainedTokenCredential 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67165101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com