public async Task <object> GetJWTToken3([FromBody] User user) { string jwtStr = string.Empty; var userInfo = await sysUserInfoServices.GetUserRoleNameStr(user.name, user.pass); var userData = await sysUserInfoServices.CheckUserInfo(user.name, user.pass); if (!string.IsNullOrEmpty(userInfo)) { //如果是基于用户的授权策略,这里要添加用户;如果是基于角色的授权策略,这里要添加角色 var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.name), new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString()) }; claims.AddRange(userInfo.Split(',').Select(s => new Claim(ClaimTypes.Role, s))); //用户标识 var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme); identity.AddClaims(claims); var token = JwtToken.BuildJwtToken(claims.ToArray(), _requirement); BasicDataUser.UserName = userData.uLoginName; BasicDataUser.UserId = userData.uID; return(new JsonResult(new { status = true, data = token, uid = userData.uID })); } else { return(new JsonResult(new { status = false, message = "认证失败" })); } }