gpt4 book ai didi

azure - 为什么使用 ClientCredential 进行 AcquireToken 失败并出现 invalid_client (ACS50012)?

转载 作者:行者123 更新时间:2023-12-04 03:58:06 24 4
gpt4 key购买 nike

为什么我的 Azure AD 应用程序不允许 oauth client_credentials 授予?

我想使用 Azure Graph API,但首先我需要一个 oauth token 。为了获取 token ,我尝试使用 Microsoft.IdentityModel.Clients.ActiveDirectory 又名 ADAL 版本 1.0.3(来自 NuGet)。

我正在使用采用 ClientCredential 对象的 AuthenticationContext.AcquireToken 重载。 (我无法使用提示用户登录的重载,因为我正在编写服务,而不是应用程序。)

我按照各种教程/示例中的说明配置了我的 Azure AD Web 应用程序(例如 ADAL - Server to Server Authentication )。

我的代码如下:

AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/thommmondago.onmicrosoft.com");
ClientCredential cc = new ClientCredential("41151135-61b8-40f4-aff7-8627e9eaf853", clientSecretKey);
AuthenticationResult result = ac.AcquireToken("https://graph.windows.net", cc);

AcquireToken行抛出异常:

sts_token_request_failed: Token request to security token service failed.  Check InnerException for more details

内部异常是一个WebException,收到的响应看起来像一个oauth错误:

{ "error":"invalid_client",
"error_description":"ACS50012: Authentication failed."
"error_codes":[50012],
"timestamp":"2014-03-17 12:26:19Z",
"trace_id":"a4ee6702-e07b-40f7-8248-589e49e96a8d",
"correlation_id":"b304af2e-2748-4067-99d0-2d7e55b121cd" }

绕过 ADAL 并将curl 与 oauth 端点一起使用也会产生相同的错误。

如果我使用我找到的 Azure 应用程序的详细信息 here,我的代码就可以工作。 :

AuthenticationContext ac = new AuthenticationContext("https://login.windows.net/graphDir1.onmicrosoft.com");
ClientCredential cc = new ClientCredential("b3b1fc59-84b8-4400-a715-ea8a7e40f4fe", "FStnXT1QON84B5o38aEmFdlNhEnYtzJ91Gg/JH/Jxiw=");
AuthenticationResult result = ac.AcquireToken("https://graph.windows.net", cc);

所以这不是我的代码的错误。我认为这要么是我的 Azure AD 错误,要么是我的 ClientCredential 参数错误。

最佳答案

结果证明这是 Windows Azure 中的一个错误,我的代码或配置没有任何问题。

微软解决了 Azure 中的问题后,我必须创建一个新的应用程序并且它开始工作。

Forum answer from Microsoft:

Hi,

We are seeing some errors with applications created in a several day time range, ending yesterday. We are continuing to fix up these applications but I don't have a good eta when this will be done. I'm apologize for the impact here.

Can you try creating a new application and retying the operation with the new client id?

thanks

关于azure - 为什么使用 ClientCredential 进行 AcquireToken 失败并出现 invalid_client (ACS50012)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22456991/

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