【发布时间】:2020-06-10 14:22:16
【问题描述】:
我正在尝试使用带有用户名/密码身份验证的 DefaultAzureCredential 对象对 Key Vault 进行身份验证,但出现此错误:
[06/10/2020 13:57:37] Exception: ClientAuthenticationError:
[06/10/2020 13:57:37] No credential in this chain provided a token.
[06/10/2020 13:57:37] Attempted credentials:
[06/10/2020 13:57:37] EnvironmentCredential: Authentication failed: Unable to find wstrust endpoint from MEX. This typically happens when attempting MSA accounts. More details available here. https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Username-Password-Authentication
[06/10/2020 13:57:37]
[06/10/2020 13:57:37] Please visit the documentation at
[06/10/2020 13:57:37] https://aka.ms/python-sdk-identity#defaultazurecredential
[06/10/2020 13:57:37] to learn what options DefaultAzureCredential supports
我可以确认正在从local.settings.json 加载所需的环境变量:
AZURE_CLIENT_IDAZURE_USERNAMEAZURE_PASSWORD
相关代码:
def encrypt(text):
uri = os.environ['KEYVAULT_URI']
credential = DefaultAzureCredential()
key_client = KeyClient(vault_url=uri, credential=credential)
key = key_client.get_key("managed-key")
crypto_client = CryptographyClient(key, credential=credential)
plaintext = text.encode()
return crypto_client.encrypt(EncryptionAlgorithm.rsa_oaep, plaintext)
local.settings.json 看起来像这样:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "{AzureWebJobsStorage}",
"KEYVAULT_URI": "<keyvault_uri>",
"AZURE_CLIENT_ID": "<client_id>",
"AZURE_USERNAME": "<email>",
"AZURE_PASSWORD": "<password>"
}
}
【问题讨论】:
标签: azure-sdk-python