oauth-2.0 - 由于 [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 获得了它们:
- https://login.microsoftonline.com/ {租户}/oauth2/authorize
- https://login.microsoftonline.com/ {租户}/oauth2/token
我在应用注册中注册了一个新应用。我使用了应用 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}
我期待着任何想法!
解决方案
您可以尝试几件事:
- 正如 Sunny 在评论中建议的那样,一个简单的步骤是在应用注册中创建一个新密钥并尝试该密钥。
- 确保您的配置或应用程序设置中的客户端密码与您在门户中的密码完全匹配。还要确保您没有以某种方式存在可能相互覆盖的重复应用程序设置。
-
转到https://identity.microsoft.com登录,然后选择您的应用程序。
点击“生成新密码”
将该值用作 client_secret 参数。
推荐阅读
- powershell - 为什么在函数中的 return 语句之后打印 Write-Host 消息?
- javascript - 是否有可用于 Umple 的 Javascript 代码生成器?
- sql-server - 如何编写 sql 代码来接受子查询中的聚合函数?
- python - 输入的Python问题
- ruby-on-rails - Rails:使用 json 类型查询审计
- google-cloud-platform - 我的 Google Cloud Platform 中是否需要组织
- c++ - 如何防止使用 std::shared_ptr 的代码中的内存泄漏
- c++ - 推回范围内的 std::vector< std::vector
> 最终耗尽所有内存 - python - Tweepy:流侦听器未捕获任何内容
- android - ListView 在滚动时加载更多