private static void AddErrors(this ProblemDetails problemDetails, IEnumerable <ErrorItem> errors)
        {
            var errorExtension = new Dictionary <string, string[]>();

            if (errors.Count() > 0)
            {
                foreach (var error in errors)
                {
                    errorExtension.Add(error.Key, error.Descriptions);
                }
            }

            problemDetails.AddExtension("errors", errorExtension);
        }
        public static ProblemDetails Generate(Microsoft.AspNetCore.Identity.SignInResult result)
        {
            var problemDetails = new ProblemDetails()
            {
                Type  = "SignInError",
                Title = "One or more errors during sign-in."
            };

            var reason = "InvalidSignIn";

            if (result.RequiresTwoFactor)
            {
                reason = "TwoFactor";
            }

            if (result.IsLockedOut)
            {
                reason = "LockedOut";
            }

            if (result.IsNotAllowed)
            {
                reason = "CredentialUnconfirmed";
            }

            problemDetails.AddExtension("reason", reason);

            if (reason == "InvalidSignIn")
            {
                problemDetails.AddErrors(new List <ErrorItem>()
                {
                    new ErrorItem()
                    {
                        Key          = "Credentials",
                        Descriptions = new string[] { "Invalid email address or password." }
                    }
                });
            }

            return(problemDetails);
        }