Azure AD B2C oauth/OpenIdConnect问题

Mag*_*ngs 6 azure openid-connect azure-ad-b2c

我对azure身份验证有一个奇怪的问题.它适用于一种情况(使用adal登录角度应用程序)但不能在其他情况下登录(加载asp.net web api并通过swagger ui授权机制登录).我把它缩小到了一个帖子:

https://login.microsoftonline.com/te/{tenantid}/oauth2/authresp
Run Code Online (Sandbox Code Playgroud)

无效返回的端点:

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>
Run Code Online (Sandbox Code Playgroud)

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

error_description = AADB2C发生了异常.

CorrelationID = 1816d2f8-aa74-4433-a7c0-d9c8fabebdb0

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

角度应用程序,完全相同的帖子,但然而返回带有令牌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>
Run Code Online (Sandbox Code Playgroud)

我看不出帖子有什么不同.这个不起作用(从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}
Run Code Online (Sandbox Code Playgroud)

但这篇文章的确如下:

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}
Run Code Online (Sandbox Code Playgroud)

由于帖子非常相同,因此问题必须存在于cookie或id令牌中(出于安全原因我无法提供).将来自两个请求的ID令牌粘贴到http://www.jwt.io中,可以获得与两者中存在的正确声明相同的信息.所以我有点卡住了,希望天蓝队的人能介入并帮忙吗?

非常感谢

Ome*_*bal 1

根据请求示例中的引荐来源网址,您似乎没有调用 /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
Run Code Online (Sandbox Code Playgroud)

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

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