为什么我的Azure AD应用程序不允许oauth client_credentials授予?
我想使用Azure Graph API,但首先我需要一个oauth令牌.要获取令牌,我正在尝试使用Microsoft.IdentityModel.Clients.ActiveDirectory又称ADAL版本1.0.3(来自NuGet).
我正在使用带有ClientCredential对象的AuthenticationContext.AcquireToken的重载.(我不能使用提示用户登录的重载,因为我正在编写服务,而不是应用程序.)
我按照各种教程/示例(例如ADAL - 服务器到服务器身份验证)中的描述配置了我的Azure AD Web应用程序.
我的代码看起来像:
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);
Run Code Online (Sandbox Code Playgroud)
该AcquireToken
行引发异常:
sts_token_request_failed: Token request to security token service failed. Check InnerException for more details
Run Code Online (Sandbox Code Playgroud)
内部异常是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" }
Run Code Online (Sandbox Code Playgroud)
绕过ADAL并使用curl和oauth端点也会产生相同的错误.
如果我使用我在此处找到的Azure应用程序的详细信息,我的代码将起作用:
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);
Run Code Online (Sandbox Code Playgroud)
因此,我的代码不是错误.我认为这是我的Azure …