gpt4 book ai didi

azure - ClientSecretCredential身份验证失败: A configuration issue is preventing authentication - check the error message from the server for details

转载 作者:行者123 更新时间:2023-12-02 05:55:00 29 4
gpt4 key购买 nike

我正在尝试使用以下代码获取服务主体的访问 token 。

$authUrl = "https://login.windows.net/" + $tenantid + "/oauth2/token/"
$body = @{
grant_type = "client_credentials"
client_id = $serviceprincipalid
resource = "https://management.azure.com/"
client_secret = $serviceprincipalkey
};
$response = Invoke-RestMethod –Uri $authUrl –Method POST –Body $body

Write-Host $response
Write-Output $response.access_token
##vso[task.setvariable variable=myToken;]$response.access_token

上面的代码在我的本地计算机的 PowerShell 上运行良好,但当我在 Azure DevOps 管道中运行相同的代码库时,它会给出以下错误。

ClientSecretCredential authentication failed: A configuration issue is preventing 
authentication - check the error message from the server for details. You can modify the
configuration in the application registration portal. See https://aka.ms/msal-net-invalid-
client for details. Original exception: AADSTS7000222: The provided client secret keys are
expired. Visit the Azure Portal to create new keys for your app, or consider using certificate
credentials for added security: https://learn.microsoft.com/azure/active-
directory/develop/active-directory-certificate-credentials
Trace ID: 98787ui7-e8ae-4712-b8b5-7678u8765rt5
Correlation ID: yhjnbv43-56sy-9ksy-b8b5-mj876yu78i90
Timestamp: 2021-03-16 12:32:28Z
There was an error with the service principal used for the deployment.`

enter image description here我检查了 key ,但 key 没有过期,它的过期日期已经设置为 2022 年。如果过期,那么代码不应该在我本地计算机的 PowerShell 上运行。

有人知道吗?请让我知道如何解决此问题。

最佳答案

嗯,实际上错误不是由上面的脚本引起的,根据我的测试,它在 devops 中运行良好。

如果您使用 Azure PowerShell task ,它会让您配置 service connection使用时,当您运行任务时,它将自动将 Azure powershell 与服务连接中配置的服务主体连接起来。该错误是由服务连接中配置的服务主体 key 过期引起的,而不是脚本中的 key 过期。

我也可以在我这边重现您的问题。

enter image description here

要解决此问题,请按照以下步骤操作。

1.导航到 Azure PowerShell 任务,检查您使用的服务连接。

enter image description here

2.导航到 devops 中的项目设置 -> 服务连接 -> 找到您使用的连接 -> 单击它 -> 管理服务主体.

然后它会打开相关的AD App页面,只需创建一个新的 secret 和服务连接,在Azure Powershell任务中使用它,按照我提到的相同步骤here .

enter image description here

3.配置完成后,再次测试,可以正常工作。

enter image description here

关于azure - ClientSecretCredential身份验证失败: A configuration issue is preventing authentication - check the error message from the server for details,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66655506/

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