Skip to content

Commit

Permalink
(identity):appsetting.json中的Jwt选项增加Token过期时间的天数配置,节点 为OSharp.Jwt.Expi…
Browse files Browse the repository at this point in the history
…reDays,数据类型为double fixed dotnetcore#62
  • Loading branch information
gmf520 committed Apr 10, 2019
1 parent 412a7a8 commit 2eaf0d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/OSharp.Permissions/Identity/JwtBearer/JwtHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 5 additions & 0 deletions src/OSharp/Core/Options/JwtOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ public class JwtOptions
/// 获取或设置 订阅方
/// </summary>
public string Audience{ get; set; }

/// <summary>
/// 获取或设置 Token有效期天数
/// </summary>
public double ExpireDays { get; set; }
}
}
3 changes: 2 additions & 1 deletion tests/web/Liuliu.Demo.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/web/Liuliu.Demo.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2eaf0d5

Please sign in to comment.