首页 > 解决方案 > 由于 [AADSTS50012:提供了无效的客户端密码],使用 Azure Active Directory 的 oAuth 失败

问题描述

我正在实现一个通过 webapi 连接到 Dynamics365 的 webapp。因此,我将 Azure Active Directory 用于 oAuth。我收到以下错误,我不确定哪里出了问题。因此,我正在描述我的整个过程:

"error":"invalid_client",
"error_description":"AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided.
      Trace ID: 2cc92fcd-798b-4636-892d-0c3c397c0401
      Correlation ID: f3bd2f4c-05c5-4de8-ace2-acf4b99e6fb9
      Timestamp: 2018-09-19 09:43:38Z",
"error_codes":[70002,50012],
"timestamp":"2018-09-19 09:43:38Z",
"trace_id":"2cc92fcd-798b-4636-892d-0c3c397c0401",
"correlation_id":"f3bd2f4c-05c5-4de8-ace2-acf4b99e6fb9"

我正在使用这些网址,包括租户。我从 Azure Portal / Azure Active Directory / App Registration 获得了它们:

我在应用注册中注册了一个新应用。我使用了应用 ID 并创建了一个用作 client_secret 的密钥。调用 authorize-url 工作正常!然后它被重定向到我的回调。

然后我得到一个我尝试用来获取令牌的代码。但它返回上面提到的错误。对 /oauth2/token 的 POST 请求的输入如下:

grant_type=authorization_code&
client_id={same as for authorize}&
code={returned code from authorize}&
redirect_uri={the callback of my webapp}&
resource={also callback-url}&
client_secret={the key from the keys-section in App Registration}

我期待着任何想法!

标签: oauth-2.0azure-active-directorydynamics-365

解决方案


您可以尝试几件事:

  1. 正如 Sunny 在评论中建议的那样,一个简单的步骤是在应用注册中创建一个新密钥并尝试该密钥。
  2. 确保您的配置或应用程序设置中的客户端密码与您在门户中的密码完全匹配。还要确保您没有以某种方式存在可能相互覆盖的重复应用程序设置。
  3. MSDN 上的类似讨论中

    1. 转到https://identity.microsoft.com登录,然后选择您的应用程序。

    2. 点击“生成新密码”

    3. 将该值用作 client_secret 参数。


推荐阅读