Das*_*ash 8 c# azure openid-connect azure-ad-b2c asp.net-core-2.2
我正在尝试在我的应用程序中处理“重置密码”用户流程。单击“忘记密码”链接后,成功触发了 OnRemoteFailure OpenId 事件,成功重定向到指定的 url 'Home/ResetPassword',但不是重定向到 ADB2C 重置密码屏幕,而是重定向回登录/登录上页。
注册/登录策略成功运行,但根据 Microsoft 文档:https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-policies:
"使用本地帐户注册或登录的用户流程在体验的第一页包含忘记密码?链接。单击此链接不会自动触发密码重置用户流程。
相反,错误代码 AADB2C90118 会返回到您的应用程序。您的应用程序需要通过运行重置密码的特定用户流来处理此错误代码。要查看示例,请查看一个简单的 ASP.NET 示例,该示例演示了用户流的链接。”


protected virtual Task OnRemoteFailure(RemoteFailureContext context)
{
context.HandleResponse();
// Handle the error code that Azure AD B2C throws when trying to reset a password from the login page
// because password reset is not supported by a "sign-up or sign-in policy"
if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("AADB2C90118"))
{
// If the user clicked the reset password link, redirect to the reset password route
context.Response.Redirect("/Home/ResetPassword");
}
else if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied"))
{
context.Response.Redirect("/");
}
else
{
context.Response.Redirect("/Home/Error?message=" + WebUtility.UrlEncode(context.Failure.Message));
}
return Task.FromResult(0);
}
Run Code Online (Sandbox Code Playgroud)
public IActionResult ResetPassword()
{
var redirectUrl = Url.Action(nameof(HomeController.Index), "Home");
var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureADB2COptionsExtended.PolicyAuthenticationProperty] = _adb2cOptions.ResetPasswordPolicyId;
return Challenge(properties, AzureADB2CDefaults.AuthenticationScheme);
}
Run Code Online (Sandbox Code Playgroud)

我发现很多使用 OWIN 的例子......关于 ASP.Net Core 2.2 w/ADB2C 的文档非常有限。
| 归档时间: |
|
| 查看次数: |
2593 次 |
| 最近记录: |