示例#1
0
        /*
         * Catch any failures received by the authentication middleware and handle appropriately
         */
        private static Task OnAuthenticationFailed(AuthenticationFailedNotification <OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
        {
            var protocolMessage = notification.ProtocolMessage;

            var authenticationErrorMessage = new AuthenticationErrorMessage()
            {
                Error            = protocolMessage.Error,
                ErrorDescription = protocolMessage.ErrorDescription,
                ErrorUri         = protocolMessage.ErrorUri
            };

            _oidcNotificationHandlerService.OnAuthenticationError(authenticationErrorMessage);

            notification.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 (notification.ProtocolMessage.ErrorDescription != null &&
                notification.ProtocolMessage.ErrorDescription.Contains("AADB2C90118"))
            {
                // If the user clicked the reset password link, redirect to the reset password route
                notification.Response.Redirect("/Account/ResetPassword");
            }
            else if (notification.Exception.Message == "access_denied")
            {
                notification.Response.Redirect("/");
            }
            else
            {
                notification.Response.Redirect("/Error?message=" + notification.Exception.Message + "&description=" +
                                               notification.ProtocolMessage.ErrorDescription);
            }

            return(Task.FromResult(0));
        }
示例#2
0
        /// <summary>
        ///     Handle failed authentication requests by redirecting the user to the home page with an error in the query string
        /// </summary>
        /// <param name="notification"></param>
        /// <returns></returns>
        private static Task OnAuthenticationFailed(
            AuthenticationFailedNotification <Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
        {
            AuthenticationErrorMessage message = new AuthenticationErrorMessage();

            //The reason:
            Exception exception = notification.Exception;


            message.Error = notification.ProtocolMessage.Error;

            AppDependencyLocator.Current.GetInstance <IOIDCNotificationHandlerService>().OnAuthenticationError(message);


            notification.HandleResponse();
            notification.Response.Redirect("/?errormessage=" + notification.Exception.Message);
            return(Task.FromResult(0));
        }
 public void OnAuthenticationError(AuthenticationErrorMessage authenticationErrorMessage)
 {
     //throw new NotImplementedException();
 }