在Razor页面Web应用程序中注册时出现AD B2C Invalid_grant错误



我在注册期间使用Azure AD B2C的Razor页面web应用程序中遇到以下错误";AADB2C90088:尚未为此终结点颁发提供的授予。实际值:B2C_ 1A_

我正在为登录和注册使用单独的B2C自定义策略。我还创建了一个单独的AccountController,它在AuthenticationProperties中设置PolicyName并调用Challenge方法。

public IActionResult SignIn(
[FromRoute] string scheme,
[FromQuery] string redirectUri)
{
scheme ??= OpenIdConnectDefaults.AuthenticationScheme;
string redirect;
if (!string.IsNullOrEmpty(redirectUri) && Url.IsLocalUrl(redirectUri))
{
redirect = redirectUri;
}
else
{
redirect = Url.Content("~/")!;
}
var properties = new AuthenticationProperties { RedirectUri = redirect };
properties.Items[Constants.Policy] = _configuration.GetValue<string>($"AzureAdB2C:SignInPolicyId");
return Challenge(properties, scheme);
}

该策略包含简单的注册&签署技术简介。SignUp流运行良好,但当它从B2C重定向到web应用程序时,会抛出Invalid grant错误。

AppSettings.json

"AzureAdB2C": {
"CallbackPath": "/signin-oidc",
"Instance": "https://xxx.b2clogin.com/",
"ClientId": "xxx",
"TenantId": "xxx",
"Domain": "xxx.onmicrosoft.com",
"SignedOutCallbackPath": "/signout/B2C_1A_SIGNIN",
"SignUpSignInPolicyId": "B2C_1A_SIGNIN",
"SignInPolicyId": "B2C_1A_SIGNIN",
"SignUpPolicyId": "B2C_1A_SIGNUP",
"SignInUrl": "/CustomIdentity/Account/SignIn?redirectUri={0}",
"SignOutUrl": "/CustomIdentity/Account/SignOut?redirectUri={0}",
"SignUpUrl": "/CustomIdentity/Account/SignUp?redirectUri={0}"
}
where, CustomIdentity/Account is the AccountController.

有人能在这个问题上帮忙吗?我不确定哪里出了问题。我对IdToken进行了调试,该令牌是通过监听OpenIdConnectOptions.Events.OnAuthorizationCodeReceived事件在Web应用程序中获得的。在解码jwt.ms中的IdToken时,它的acr声明为B2C_1A_SIGNUP。我不确定B2C_1A_SIGNIN的实际值是从哪里返回的。

如有任何帮助,我们将不胜感激。

谢谢!

解决方案是将注册和登录策略合并为一个可以同时处理这两个策略的策略。合并策略后解决了所有问题。

最新更新