hutongqing
2024-08-28 d0f01f571918ae942349068776fa7fb70f3ab5cd
WIDESEAWCS_Server/WIDESEAWCS_Core/Authorization/JwtHelper.cs
@@ -23,7 +23,7 @@
        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()}"),
@@ -33,12 +33,13 @@
                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);
@@ -112,7 +113,9 @@
        /// <summary>
        /// 职能
        /// </summary>
        public string Work { get; set; }
        public string UserName { get; set; }
        public long TenantId { get; set; }
    }
}