✅ Authentication with Cookies
I'm playing around with cookies to get a better understanding. My code:
Currently, the
user-info
endpoint returns "empty" after getting a cookie from the login
endpoint. When I changed to AddCookie("cookie")
, and change the ClaimsIdentity and Signin to "cookie", it returns a claim value. I was under the impression I could name the AddCookie
scheme whatever I would like. Could someone please explain?10 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yep, a cookie called .AspNetCore.local
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Hmmm no the ctx.User.Claims doesn't contain any claims. When I switch "local" for "cookie" in all places, it adds the claim
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Isnt that expected? SignInAsync doesnt take the cookie name, it takes the login auth schema
which is "cookie" here
I tried this, but get this exception
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.authenticationservicecollectionextensions.addauthentication?view=aspnetcore-7.0#microsoft-extensions-dependencyinjection-authenticationservicecollectionextensions-addauthentication(microsoft-extensions-dependencyinjection-iservicecollection-system-string)
in the code block you pasted above, you are adding "cookie" as your fallback signin schema, then adding a new cookie schema called "local"
ah it seems I was misunderstanding. I thought the fallback signin schema meant the type of schema, for instance cookie or JWT. I didn't realize it had to match one of the names of the schemas adding, i thought it meant the type
thank you both!
Closed!