public async Task <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 var authProp = new AuthenticationProperties() { RedirectUri = "/" }; authProp.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = azureOptions.ResetPasswordPolicyId; await context.HttpContext.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, authProp); } else if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied")) { context.Response.Redirect("/"); } else { context.Response.Redirect("/Home/Error"); } return(Task.CompletedTask); }
/// <summary>Handles the remote failure.</summary> /// <param name="context">The context.</param> /// <returns>A task.</returns> /// <exception cref="ArgumentNullException"><paramref name="context"/> is <see langword="null"/>.</exception> public static Task HandleRemoteFailure(this RemoteFailureContext context) { if (context == default) { throw new ArgumentNullException(nameof(context)); } if (context.Properties.Items.ContainsKey(Referer)) { context.Response.Redirect($"{context.Properties.Items[Referer]}"); } context.HandleResponse(); return(CompletedTask); }
public 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("/Account/ResetPassword"); } else if (context.Failure is OpenIdConnectProtocolException && context.Failure.Message.Contains("access_denied")) { context.Response.Redirect("/"); } else { context.Response.Redirect("/Home/Error"); } return(Task.CompletedTask); }