优化代码

This commit is contained in:
不做码农
2022-01-08 21:48:09 +08:00
parent 3fee68d504
commit 58bbb2b967
5 changed files with 19 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
using Infrastructure;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
@@ -74,7 +75,10 @@ namespace ZR.Admin.WebApi.Framework
{
JwtSettings jwtSettings = new();
ConfigUtils.Instance.Bind("JwtSettings", jwtSettings);
if (jwtSettings == null || jwtSettings.SecretKey.IsEmpty())
{
return null;
}
var key = Encoding.ASCII.GetBytes(jwtSettings.SecretKey);
var tokenDescriptor = new TokenValidationParameters
@@ -125,8 +129,8 @@ namespace ZR.Admin.WebApi.Framework
{
try
{
var userId = jwtToken.FirstOrDefault(x => x.Type == "primarysid").Value;
var userName = jwtToken.FirstOrDefault(x => x.Type == "unique_name").Value;
//var userId = jwtToken.FirstOrDefault(x => x.Type == "primarysid").Value;
//var userName = jwtToken.FirstOrDefault(x => x.Type == "unique_name").Value;
var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value;
LoginUser loginUser = JsonConvert.DeserializeObject<LoginUser>(userData);