Skip to content

Better error message for AntiforgeryValidationException: The provided antiforgery token was meant for a different claims-based user than the current userΒ #63218

@davhdavh

Description

@davhdavh

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

AntiforgeryValidationException: The provided antiforgery token was meant for a different claims-based user than the current user is incrediable annoying because it gives you very little actual information about what is going on...

A VERY common issue is that someone put .UseAntiforgery() before .UseAuth..., and it would be really if the error message could catch this very common case.

Describe the solution you'd like

if (!comparer.Equals(requestToken.Username, currentUsername))

should report a different error if httpContext.User.IsAuthenticated == false, example AntiforgeryValidationException: The provided antiforgery token was meant for an authenticated user, but current user is not authenticated. Did you put .UseAntiforgery() after .UseAuthentication()?.

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions