public static IActionResult IdentityFailure(this ControllerBase controller, string code, string description)
        {
            var result = IdentityResult.Failed(new IdentityError()
            {
                Code = code, Description = description
            });

            return(controller.BadRequest(ProblemDetailsGenerators.Generate(result)));
        }
        public static IActionResult SignInFailure(this ControllerBase controller, Microsoft.AspNetCore.Identity.SignInResult result)
        {
            var problemDetails = ProblemDetailsGenerators.Generate(result);

            if ((string)problemDetails.Extensions["reason"] == "InvalidSignIn")
            {
                return(controller.BadRequest(problemDetails));
            }

            return(controller.Unauthorized(problemDetails));
        }
Esempio n. 3
0
 public static IServiceCollection AddControllerErrorHelpers(this IServiceCollection services)
 {
     return(services.Configure <ApiBehaviorOptions>(options =>
                                                    options.InvalidModelStateResponseFactory = context =>
                                                                                               new BadRequestObjectResult(ProblemDetailsGenerators.Generate(context.ModelState))));
 }
 public static IActionResult BadModel(this ControllerBase controller)
 {
     return(controller.BadRequest(ProblemDetailsGenerators.Generate(controller.ModelState)));
 }
 public static IActionResult IdentityFailure(this ControllerBase controller, IdentityResult result)
 {
     return(controller.BadRequest(ProblemDetailsGenerators.Generate(result)));
 }