riokei, 1 year ago As a newbie dev learning #csharp and #dotNET , I've built a project or two with #MVC but have no idea how to implement a demo log-in for it. can anyone who sees this offer some advice?
As a newbie dev learning #csharp and #dotNET , I've built a project or two with #MVC but have no idea how to implement a demo log-in for it. can anyone who sees this offer some advice?
khalidabuhakmeh, 1 year ago @riokei For demoes, simply using the SignInAsync and setting the User is enough to trigger auth. After setting up your auth settings, it's as simple as having the following code. var identity = new ClaimsIdentity(); identity.AddClaim(new Claim(ClaimTypes.Name, "khalid.abuhakmeh")); identity.AddClaim(new Claim(ClaimTypes.Authentication, "Cookie")); // write auth cookie await ctx.SignInAsync(new ClaimsPrincipal(new[] { identity }));
@riokei For demoes, simply using the SignInAsync and setting the User is enough to trigger auth.
SignInAsync
After setting up your auth settings, it's as simple as having the following code.
var identity = new ClaimsIdentity(); identity.AddClaim(new Claim(ClaimTypes.Name, "khalid.abuhakmeh")); identity.AddClaim(new Claim(ClaimTypes.Authentication, "Cookie")); // write auth cookie await ctx.SignInAsync(new ClaimsPrincipal(new[] { identity }));
riokei, 1 year ago @khalidabuhakmeh Thank you so much!
@khalidabuhakmeh Thank you so much!
khalidabuhakmeh, 1 year ago @riokei If you get stuck let me know. The annoying part is setting up the auth providers for cookie auth and being sure it looks at a claim. Oh, and always add a claim for authentication type, which is used to trigger the boolean "IsAuthenticated" in most cases.
@riokei If you get stuck let me know. The annoying part is setting up the auth providers for cookie auth and being sure it looks at a claim.
Oh, and always add a claim for authentication type, which is used to trigger the boolean "IsAuthenticated" in most cases.
riokei, 1 year ago @khalidabuhakmeh will do! I'll make sure to check that as well.
@khalidabuhakmeh will do! I'll make sure to check that as well.
riokei, 1 year ago @khalidabuhakmeh I got it working thanks!
@khalidabuhakmeh I got it working thanks!
khalidabuhakmeh, 1 year ago @riokei Awesome! 👍
@riokei Awesome! 👍
Add comment