Replies: 2 comments 2 replies
-
@javiercn any thoughts here? |
Beta Was this translation helpful? Give feedback.
-
Not sure if the docs here have it, but essentially, someone from another origin can force a post request without you knowing and logging the user out, although this is less prevalent these days since most browsers support samesite cookies, which prevent this too.
It comes down to a matter of preference. Razor pages perform antiforgery validation by default, while in MVC is an opt-in feature. That is because Razor pages are explicitly designed to write UI code while MVC controllers are more flexible and allow you to write UI code and APIs, so performing antiforgery validation by default would be cumbersome for API authors (they would have to disable it, not to mention it was not on by default for historical reasons and turning it on by default would break a lot of customers apps). I wouldn't pay too much attention to the samples in the asp.net core repo, in many cases they are a playground for features and don't necessarily reflect best practices. I believe there are more "canonical" sample apps in the docs. |
Beta Was this translation helpful? Give feedback.
-
Looking to add GitHub based authentication to a razor site that I run. Could not find any solid tutorials on the web for doing this. Instead I started at the OAuth Providers site and worked out authentication from there.
The samples there are good but they're still based in MVC. There was no example on how to do it with only Razor pages and / or hand route mapping. I managed to get it working though here. That commit is basically the delta between
dotnet new razor
and getting GitHub authentication working.Even though I have it working now I still have a few questions:
SignOut
page just so I could usePageModel.SignOut
. That feels really heavy weight and indirect particularly because signing out really doesn't have a UI. My instinct was that I should useendPoints.MapPost("/signout", ...)
but I could not find a way to actually sign out from that context. Is there a way to do this or do I need to define a page in order to sign out?Thanks for any help here.
Note: I'm brand new to both razor and authentication so if u think I'm doing something incredibly wrong please make sure to say so because I probably am 😄
Beta Was this translation helpful? Give feedback.
All reactions