aaarianme
aaarianme

Reputation: 282

How to assign a user manually

I have all the claims and i have also checked if the token is valid. How do i signin this new user with IsAuthenticated=true and the claims principals

            var tokenHandler = new JwtSecurityTokenHandler();
            var validationParameters = new TokenValidationParameters()
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(conf.GetSection("JWTKey").Value)),
                ValidateAudience = false,
                ValidateIssuer = false
            }
            ;

            SecurityToken validatedToken;
            IPrincipal pr= tokenHandler.ValidateToken(token, validationParameters, out validatedToken);

            var claims = tokenHandler.ReadJwtToken(token).Claims;
            var claimspr = new ClaimsPrincipal(new ClaimsIdentity(cliams,"JWTAuth"));

Upvotes: 0

Views: 82

Answers (1)

Ask
Ask

Reputation: 3746

As you're using .net core. You can use HttpContext.SignInAsyncand pass ClaimsPrincipal as a param.See this

Upvotes: 1

Related Questions