1、生成JWT的输出token
var claims = new[] { new Claim(ClaimTypes.Name, "Celon"), new Claim(ClaimTypes.Role, "Admin") }; var option = _options.Value; var token = new JwtSecurityToken ( issuer: option.Issuer, audience: option.Audience, claims: claims, expires: DateTime.Now.AddMinutes(60), signingCredentials: option.SigningCredentials ); var outputToken = new JwtSecurityTokenHandler().WriteToken(token);
2、解析token
var jwt = new JwtSecurityToken(token);