Check Token in .NET Core

2021年8月12日 44点热度 0人点赞 0条评论
内容目录

When directly using the API to get a Claim, the correctness of the Token's key is not checked.

                var jwt = jwtSecurityTokenHandler.ReadJwtToken(token);

If you want to check the Token at the same time, you can use the following:

                // Check the key
                ClaimsPrincipal claimsPrincipal = jwtSecurityTokenHandler.ValidateToken(token, new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = SecurityKey,
                    ValidateIssuer = false,
                    ValidateAudience = false,
                    ClockSkew = TimeSpan.Zero
                }, out SecurityToken securityToken);

痴者工良

高级程序员劝退师

文章评论