riokei,

As a newbie dev learning and , I've built a project or two with but have no idea how to implement a demo log-in for it. can anyone who sees this offer some advice?

khalidabuhakmeh,
@khalidabuhakmeh@mastodon.social avatar

@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,

@khalidabuhakmeh Thank you so much!

khalidabuhakmeh,
@khalidabuhakmeh@mastodon.social avatar

@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,

@khalidabuhakmeh will do! I'll make sure to check that as well.

riokei,

@khalidabuhakmeh I got it working thanks!

khalidabuhakmeh,
@khalidabuhakmeh@mastodon.social avatar

@riokei Awesome! 👍

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • InstantRegret
  • slotface
  • osvaldo12
  • kavyap
  • khanakhh
  • Durango
  • megavids
  • everett
  • tacticalgear
  • modclub
  • normalnudes
  • ngwrru68w68
  • cisconetworking
  • tester
  • GTA5RPClips
  • Leos
  • anitta
  • provamag3
  • JUstTest
  • lostlight
  • All magazines