Skip to content

BlazorWeb antiforgery issue on SignInAsync. #50760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
ssperoniGIT opened this issue Sep 17, 2023 · 3 comments
Closed
1 task done

BlazorWeb antiforgery issue on SignInAsync. #50760

ssperoniGIT opened this issue Sep 17, 2023 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@ssperoniGIT
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The edit form already has AntiforgeryToken >.

Login with httpContext.SignInAsync, then logout with httpContext.SignOutAsync.
Then login again from same page.
I get the following msg:
'A valid antiforgery token was not provided with the request. Add an antiforgery token, or disable antiforgery validation for this endpoint.'

Expected Behavior

Be able to Login a second time from same page.

Steps To Reproduce

Project with minimal code;
https://github.com/ssperoniGIT/BlazorWeb-antiforgery-issue-on-login.

chrome-capture-2023-8-17b

Exceptions (if any)

No response

.NET Version

8-rc.1

Anything else?

No response

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Sep 17, 2023
@Kahbazi
Copy link
Member

Kahbazi commented Sep 17, 2023

@ssperoniGIT I'm not 100% sure, but this might solve the problem.

Tokens should be refreshed after the user is authenticated by redirecting the user to a view or Razor Pages page.

https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-7.0#refresh-tokens-after-authentication-1

@ssperoniGIT
Copy link
Author

I added a Razor Page to the Blazor-ssr project. However, I was unable to find a way to navigate to the Razor Page so could not test this. Perhaps someone could give us guidance on Blazor-ssr cookie authentication.

@javiercn
Copy link
Member

This is caused by the implicit antiforgery middleware, you can use app.UseAntiforgery() after app.UseAuthentication() to workaround it. We are going to use #50818 to track it

@javiercn javiercn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants