JWT使用---来源practical-aspnetcore项目

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);

 

JWT使用---来源practical-aspnetcore项目

上一篇:复制、移动、删除、软链接、硬链接原理


下一篇:虚拟机centos无法进去选择系统界面,也就是开机过bios就黑屏解决方案