Посмотрев на него, я увидел, что оно устанавливает IAntiForgeryValidationFeature с ошибкой при проверке. не удалось, поэтому я создал промежуточное программное обеспечение, чтобы это проверить.
Код: Выделить всё
public class CustomAntiForgeryValidationResponseMiddleware(RequestDelegate next)
{
public async Task InvokeAsync(HttpContext context)
{
IAntiforgeryValidationFeature? antiforgeryValidation = context.Features.Get();
if (antiforgeryValidation is not null && !antiforgeryValidation.IsValid)
{
context.Response.StatusCode = 403;
await context.Response.WriteAsJsonAsync(new ProblemDetails()
{
Title = "Forbidden",
Detail = "User is not allowed to perform this action",
Status = 403,
Extensions = new Dictionary()
{
{ "errors", new ApiError[] { new("Invalid or missing CSRF token") } }
}
});
}
await next(context);
}
}
Код: Выделить всё
app.UseMiddleware();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-response
Мобильная версия