diff --git a/src/OSharp.Permissions/Identity/JwtBearer/JwtHandler.cs b/src/OSharp.Permissions/Identity/JwtBearer/JwtHandler.cs index 1da7b5f80..664f523c1 100644 --- a/src/OSharp.Permissions/Identity/JwtBearer/JwtHandler.cs +++ b/src/OSharp.Permissions/Identity/JwtBearer/JwtHandler.cs @@ -41,7 +41,8 @@ public static string CreateToken(Claim[] claims, OsharpOptions options) SecurityKey key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secret)); SigningCredentials credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature); DateTime now = DateTime.Now; - DateTime expires = now.AddDays(7); //todo: 启用系统设置功能,在后台设置这些参数 + double days = Math.Abs(jwtOptions.ExpireDays) > 0 ? Math.Abs(jwtOptions.ExpireDays) : 7; + DateTime expires = now.AddDays(days); SecurityTokenDescriptor descriptor = new SecurityTokenDescriptor { diff --git a/src/OSharp/Core/Options/JwtOptions.cs b/src/OSharp/Core/Options/JwtOptions.cs index 9547d06d5..2ccd5eab8 100644 --- a/src/OSharp/Core/Options/JwtOptions.cs +++ b/src/OSharp/Core/Options/JwtOptions.cs @@ -28,5 +28,10 @@ public class JwtOptions /// 获取或设置 订阅方 /// public string Audience{ get; set; } + + /// + /// 获取或设置 Token有效期天数 + /// + public double ExpireDays { get; set; } } } \ No newline at end of file diff --git a/tests/web/Liuliu.Demo.Web/appsettings.Development.json b/tests/web/Liuliu.Demo.Web/appsettings.Development.json index 9e961ea2b..f549471d6 100644 --- a/tests/web/Liuliu.Demo.Web/appsettings.Development.json +++ b/tests/web/Liuliu.Demo.Web/appsettings.Development.json @@ -83,7 +83,8 @@ "Jwt": { "Issuer": "osharp identity", "Audience": "osharp angular demo", - "Secret": "{8619F7C3-B53C-4B85-99F0-983D351ECD82}" + "Secret": "{8619F7C3-B53C-4B85-99F0-983D351ECD82}", + "ExpireDays": 1.0 }, "Redis": { "Configuration": "localhost", diff --git a/tests/web/Liuliu.Demo.Web/appsettings.json b/tests/web/Liuliu.Demo.Web/appsettings.json index 8a20bb74a..7f4674ce0 100644 --- a/tests/web/Liuliu.Demo.Web/appsettings.json +++ b/tests/web/Liuliu.Demo.Web/appsettings.json @@ -26,7 +26,8 @@ "Jwt": { "Issuer": "osharp identity", "Audience": "osharp angular demo", - "Secret": "{8619F7C3-B53C-4B85-99F0-983D351ECD82}" + "Secret": "{8619F7C3-B53C-4B85-99F0-983D351ECD82}", + "ExpireDays": 7.0 }, "MailSender": { "Host": "smtp.66soft.net",