InvalidOperationException when trying to make SignInAsync

I am trying to sign a user in a regular controller. I have something like:

var claims = new List<Claim> { new Claim(JwtClaimTypes.Subject, "xxx-xxx-xx-xxx), new Claim(JwtClaimTypes.PreferredUserName, "someusername"), new Claim(JwtClaimTypes.Email, " foo@bar "), new Claim(JwtClaimTypes.EmailVerified, " foo@bar :), new Claim(JwtClaimTypes.IdentityProvider, "idsvr"), }; var ci = new ClaimsIdentity(claims, "password", JwtClaimTypes.PreferredUserName, JwtClaimTypes.Role); var cp = new ClaimsPrincipal(ci); await HttpContext.Authentication.SignInAsync("myscheme", cp); 

And I get an exception saying InvalidOperationException: name claim is missing

In the ClaimsIdentity constructor, I indicated that my name request was JwtClaimTypes.PreferredUsername (which is "preferred_username")

If I add a claim for a name to the claims list, log in using the above code snippet. However, in reality, we do not have names in our system. We want to use "preferred_username" as a name application in abstractions.

+6
source share

Source: https://habr.com/ru/post/1014987/


All Articles