mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2024-09-20 23:48:27 +08:00
🐛 优化JWT签发属性 iat 为签发时间戳
This commit is contained in:
parent
7ca3e1ec22
commit
6331e20820
|
@ -70,7 +70,7 @@ namespace Blog.Core.Controllers
|
|||
var user = await _sysUserInfoServices.GetUserRoleNameStr(name, MD5Helper.MD5Encrypt32(pass));
|
||||
if (user != null)
|
||||
{
|
||||
TokenModelJwt tokenModel = new TokenModelJwt { Uid = 1, Role = user };
|
||||
TokenModelJwt tokenModel = new TokenModelJwt {Uid = 1, Role = user};
|
||||
|
||||
jwtStr = JwtHelper.IssueJwt(tokenModel);
|
||||
suc = true;
|
||||
|
@ -121,7 +121,7 @@ namespace Blog.Core.Controllers
|
|||
|
||||
var result = new
|
||||
{
|
||||
data = new { success = suc, token = jwtStr }
|
||||
data = new {success = suc, token = jwtStr}
|
||||
};
|
||||
|
||||
return new MessageModel<string>()
|
||||
|
@ -164,7 +164,7 @@ namespace Blog.Core.Controllers
|
|||
new Claim(ClaimTypes.Name, name),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, user.FirstOrDefault().Id.ToString()),
|
||||
new Claim("TenantId", user.FirstOrDefault().TenantId.ToString()),
|
||||
new Claim(JwtRegisteredClaimNames.Iat, DateTime.Now.ToString()),
|
||||
new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.Now.ToUnixTimeSeconds().ToString()),
|
||||
new Claim(ClaimTypes.Expiration,
|
||||
DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString())
|
||||
};
|
||||
|
@ -236,7 +236,7 @@ namespace Blog.Core.Controllers
|
|||
{
|
||||
new Claim(ClaimTypes.Name, user.LoginName),
|
||||
new Claim(JwtRegisteredClaimNames.Jti, tokenModel.Uid.ObjToString()),
|
||||
new Claim(JwtRegisteredClaimNames.Iat, DateTime.Now.ToString()),
|
||||
new Claim(JwtRegisteredClaimNames.Iat, DateTimeOffset.Now.ToUnixTimeSeconds().ToString()),
|
||||
new Claim(ClaimTypes.Expiration,
|
||||
DateTime.Now.AddSeconds(_requirement.Expiration.TotalSeconds).ToString())
|
||||
};
|
||||
|
@ -305,7 +305,7 @@ namespace Blog.Core.Controllers
|
|||
{
|
||||
if (loginRequest is null)
|
||||
{
|
||||
return new { result = false };
|
||||
return new {result = false};
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -315,7 +315,7 @@ namespace Blog.Core.Controllers
|
|||
{
|
||||
HttpContext.SuccessSwagger();
|
||||
HttpContext.SuccessSwaggerJwt(result.response.token);
|
||||
return new { result = true };
|
||||
return new {result = true};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -323,7 +323,7 @@ namespace Blog.Core.Controllers
|
|||
_logger.LogWarning(ex, "Swagger登录异常");
|
||||
}
|
||||
|
||||
return new { result = false };
|
||||
return new {result = false};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -334,7 +334,7 @@ namespace Blog.Core.Controllers
|
|||
[Route("wxLogin")]
|
||||
public dynamic WxLogin(string g = "", string token = "")
|
||||
{
|
||||
return new { g, token };
|
||||
return new {g, token};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,8 @@ namespace Blog.Core
|
|||
/// <returns></returns>
|
||||
public static bool IsNotEmptyOrNull(this object thisValue)
|
||||
{
|
||||
return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" && ObjToString(thisValue) != "null";
|
||||
return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" &&
|
||||
ObjToString(thisValue) != "null";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -122,7 +123,8 @@ namespace Blog.Core
|
|||
return errorValue;
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(this object thisValue) => thisValue == null || thisValue == DBNull.Value || string.IsNullOrWhiteSpace(thisValue.ToString());
|
||||
public static bool IsNullOrEmpty(this object thisValue) => thisValue == null || thisValue == DBNull.Value ||
|
||||
string.IsNullOrWhiteSpace(thisValue.ToString());
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -169,6 +171,16 @@ namespace Blog.Core
|
|||
{
|
||||
reval = Convert.ToDateTime(thisValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
//时间戳转为时间
|
||||
var seconds = ObjToLong(thisValue);
|
||||
if (seconds > 0)
|
||||
{
|
||||
var startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
|
||||
reval = startTime.AddSeconds(Convert.ToDouble(thisValue));
|
||||
}
|
||||
}
|
||||
|
||||
return reval;
|
||||
}
|
||||
|
@ -235,7 +247,7 @@ namespace Blog.Core
|
|||
{
|
||||
Type innerType = type.GetGenericArguments()[0];
|
||||
object innerValue = ChangeType(value, innerType);
|
||||
return Activator.CreateInstance(type, new object[] { innerValue });
|
||||
return Activator.CreateInstance(type, new object[] {innerValue});
|
||||
}
|
||||
|
||||
if (value is string && type == typeof(Guid)) return new Guid(value as string);
|
||||
|
@ -278,7 +290,7 @@ namespace Blog.Core
|
|||
.Remove(split.Length - 2, 1);
|
||||
}
|
||||
|
||||
addMethod.Invoke(lis, new object[] { ChangeType(str, type) });
|
||||
addMethod.Invoke(lis, new object[] {ChangeType(str, type)});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user