| | |
| | | public static string IssueJwt(TokenModelJwt tokenModel) |
| | | { |
| | | string exp = $"{new DateTimeOffset(DateTime.Now.AddMinutes(/*tokenModel.UserId == 1 ? 43200 : */AppSettings.app("ExpMinutes").ObjToInt())).ToUnixTimeSeconds()}"; |
| | | var claims = new List<Claim> |
| | | List<Claim> claims = new List<Claim> |
| | | { |
| | | new Claim(JwtRegisteredClaimNames.Jti,tokenModel.UserId.ToString()), |
| | | new Claim(JwtRegisteredClaimNames.Iat, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"), |
| | |
| | | new Claim (JwtRegisteredClaimNames.Exp,exp), |
| | | new Claim(JwtRegisteredClaimNames.Iss,AppSecret.Issuer), |
| | | new Claim(JwtRegisteredClaimNames.Aud,AppSecret.Audience), |
| | | new Claim(ClaimTypes.Role, tokenModel.RoleId.ToString()) |
| | | new Claim(ClaimTypes.Role, tokenModel.RoleId.ToString()), |
| | | new Claim(ClaimTypes.Name, tokenModel.UserName), |
| | | new Claim(nameof(TokenModelJwt.TenantId), tokenModel.TenantId.ToString()) |
| | | }; |
| | | |
| | | // 可以将一个用户的多个角色全部赋予; |
| | | // 作者:DX 提供技术支持; |
| | | |
| | | //秘钥16位 |
| | | var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AppSecret.JWT)); |
| | | var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); |
| | |
| | | /// <summary> |
| | | /// 职能 |
| | | /// </summary> |
| | | public string Work { get; set; } |
| | | public string UserName { get; set; } |
| | | |
| | | public long TenantId { get; set; } |
| | | |
| | | } |
| | | } |