Azure AD B2C 问题 oauth/OpenIdConnect
Issue with Azure AD B2C oauth/OpenIdConnect
我对 Azure 身份验证有一个奇怪的问题。它适用于一种情况(使用 adal 使用 angular 应用程序登录)但不适用于另一种情况(加载 asp.net 网络 api 并通过 swagger ui 登录授权机制)。我已将范围缩小到 post 到:
https://login.microsoftonline.com/te/{tenantid}/oauth2/authresp
没有帮助的端点returns:
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&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&state={ommitted}">here</a>.</h2>
</body>
</html>
基本上告诉我发生了异常。
error_description = AADB2C 发生异常。
CorrelationID = 1816d2f8-aa74-4433-a7c0-d9c8fabebdb0
时间戳 = 2017-10-27 13:46:08
angular 应用程序的功能与 post 完全相同,但是 returns 一个 link 的令牌 ID:
302
<html>
<head>
<title>Object moved</title>
</head>
<body>
<h2>Object moved to <a href="http://localhost:4200/#state={state -
ommitted}&id_token={id token - omitted}">here</a>.
</h2>
</body>
</html>
我看不出 post 有什么不同。这个不行(从 swagger ui on web api project 发起)
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 确实:
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}
由于 post 几乎完全相同,所以问题一定出在 cookie 或 id 令牌中(出于安全原因我无法提供)。将两个请求中的 ID 令牌粘贴到 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 身份验证有一个奇怪的问题。它适用于一种情况(使用 adal 使用 angular 应用程序登录)但不适用于另一种情况(加载 asp.net 网络 api 并通过 swagger ui 登录授权机制)。我已将范围缩小到 post 到:
https://login.microsoftonline.com/te/{tenantid}/oauth2/authresp
没有帮助的端点returns:
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&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&state={ommitted}">here</a>.</h2>
</body>
</html>
基本上告诉我发生了异常。
error_description = AADB2C 发生异常。
CorrelationID = 1816d2f8-aa74-4433-a7c0-d9c8fabebdb0
时间戳 = 2017-10-27 13:46:08
angular 应用程序的功能与 post 完全相同,但是 returns 一个 link 的令牌 ID:
302
<html>
<head>
<title>Object moved</title>
</head>
<body>
<h2>Object moved to <a href="http://localhost:4200/#state={state -
ommitted}&id_token={id token - omitted}">here</a>.
</h2>
</body>
</html>
我看不出 post 有什么不同。这个不行(从 swagger ui on web api project 发起)
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 确实:
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}
由于 post 几乎完全相同,所以问题一定出在 cookie 或 id 令牌中(出于安全原因我无法提供)。将两个请求中的 ID 令牌粘贴到 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 门户创建一个应用程序,然后再试一次,您应该可以解决这个问题。