azure - Azure AD B2C oauth/OpenIdConnect 问题

标签 azure openid-connect azure-ad-b2c

我在 Azure 身份验证方面遇到了一个奇怪的问题。它适用于一种场景(使用 adal 使用 Angular 应用程序登录),但不适用于另一种场景(加载 asp.net Web api 并通过 swagger ui 授权机制登录)。我已将其范围缩小到一篇帖子:

https://login.microsoftonline.com/te/{tenantid}/oauth2/authresp

毫无帮助地返回的端点:

302

<html>
 <head>
  <title>Object moved</title></head>
  <body>
   <h2>Object moved to <a href="http://localhost:49919/swagger/ui/oauth2redirect-html#error=server_error&amp;error_description=AADB2C%3a+An+exception+has+occured.%0d%0aCorrelation+ID%3a+1816d2f8-aa74-4433-a7c0-d9c8fabebdb0%0d%0aTimestamp%3a+2017-10-27+13%3a46%3a08Z%0d%0a&amp;state={ommitted}">here</a>.</h2>
</body>
</html>

基本上告诉我发生了异常。

error_description = AADB2C 发生异常。

相关 ID = 1816d2f8-aa74-4433-a7c0-d9c8fabebdb0

时间戳 = 2017-10-27 13:46:08

角度应用程序执行完全相同的帖子,但返回带有 token id 的链接:

302

<html>
  <head>
   <title>Object moved</title>
  </head>
  <body>
   <h2>Object moved to <a href="http://localhost:4200/#state={state -
   ommitted}&amp;id_token={id token - omitted}">here</a>.
    </h2>
   </body>
 </html>

我看不出帖子有任何差异。这个不起作用(从 web api 项目上的 swagger ui 启动)

POST https://login.microsoftonline.com/te/{tenant - omitted}/oauth2/authresp HTTP/1.1
Host: login.microsoftonline.com
Connection: keep-alive
Content-Length: 1595
Cache-Control: max-age=0
Origin: https://login.microsoftonline.com
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Referer: https://login.microsoftonline.com/{tenant - omitted}/oauth2/authorize?client_id={clientid - omitted}&redirect_uri=https:%2f%2flogin.microsoftonline.com%2fte%2f{tenant - omitted}%2foauth2%2fauthresp&response_type=id_token&response_mode=form_post&nonce={nonce}&state=StateProperties
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en;q=0.9,de-CH;q=0.8,de;q=0.7,fr-CH;q=0.6,fr;q=0.5,it-CH;q=0.4,it;q=0.3
Cookie: {cookie - omitted}=; x-ms-gateway-slice=005; stsservicecookie=cpim_te

id_token={omitted}

但是这篇文章确实:

POST https://login.microsoftonline.com/te/{tenant - omitted}/oauth2/authresp HTTP/1.1
Host: login.microsoftonline.com
Connection: keep-alive
Content-Length: 1590
Cache-Control: max-age=0
Origin: https://login.microsoftonline.com
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
DNT: 1
Referer: https://login.microsoftonline.com/{tenant - omitted}/oauth2/authorize?client_id={clientid - omitted}&redirect_uri=https:%2f%2flogin.microsoftonline.com%2fte%2f{tenant - omitted}%2foauth2%2fauthresp&response_type=id_token&response_mode=form_post&nonce={nonce}&state=StateProperties
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en;q=0.9,de-CH;q=0.8,de;q=0.7,fr-CH;q=0.6,fr;q=0.5,it-CH;q=0.4,it;q=0.3
Cookie: {cookie - omitted}; x-ms-gateway-slice=003; stsservicecookie=cpim_te

id_token={omitted}

由于这些帖子几乎相同,因此问题必定出在 cookie 或 id token 中(出于安全原因我无法提供)。将两个请求中的 ID token 粘贴到 http://www.jwt.io 中可以提供相同的信息,并且两个请求中都存在正确的声明。所以我有点困惑,希望 azure 团队的人可以介入并提供帮助?

非常感谢

最佳答案

根据请求示例中的引荐来源网址,您似乎没有调用/v2.0/B2C 端点。例如,在以下请求中,路径应为/{tenant}/oauth2/v2.0/authorize...

https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id={clientid}&redirect_uri=https:%2f%2flogin.microsoftonline.com%2fte%2f{tenant}%2foauth2%2fauthresp&response_type=id_token&response_mode=form_post&nonce={nonce}&state=StateProperties

因此,您的两个应用程序都会出现意外行为。这也意味着您正在使用的应用程序不是使用 B2C 门户创建的(我们也通过离线聊天验证了这一点)。

到目前为止,B2C 仅支持通过 B2C 门户创建的应用程序。因此,如果您可以通过 B2C 门户创建一个应用程序,然后重试,您应该可以解决此问题。

关于azure - Azure AD B2C oauth/OpenIdConnect 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46977245/

相关文章:

Azure B2C 租户失败,错误为 "Tenant creation failed."

php - {R :1} and {C:1} on iis web. 配置文件之间的差异

amazon-web-services - AWS Cognito 中的 Microsoft oidc 允许多个租户

tomcat - 将 TCP 流量路由到 Azure VM 上的端口 8080

node.js - Node express 与 OpenID 连接

ios - 如何使用 AppAuth 从 iOS 应用程序向 Azure AD 进行身份验证?

Azure AD B2C 自定义属性显示为空

c# - 如何使用 ADB2C 实现身份验证端点

azure - Azure 应用服务中的 LDAP 身份验证失败

javascript - 如何在版本 ^3 上使用 gremlin 启动与 Cosmos DB 图形数据库的新连接