chenhaozhe
7 天以前 25dc8c13144cc891bbc467fefb8b2dac1d0c8dd1
WebAPI/Utility/JWTHelper.cs
@@ -26,8 +26,8 @@
        {
            var claims = new[]
            {
            new Claim(ClaimTypes.NameIdentifier, userId),
            new Claim(ClaimTypes.Name, userName),
            new Claim(ClaimTypes.NameIdentifier, userId), // 编码
            new Claim(ClaimTypes.Name, userName), // 用户id
            new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
        };
@@ -98,5 +98,13 @@
            }
            return false;
        }
        public static String getUserName(string token)
        {
            var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token);
            var userName = jwt.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
            // 通过上一个token的值刷新token
            return userName;
        }
    }
}