aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/JwtService.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-01 22:32:40 +0800
committer杨宇千 <crupest@outlook.com>2019-08-01 22:32:40 +0800
commit308c1faa5130913428b7348f78fe0fe2c406a63d (patch)
treeabbdb97d24c2e6d7c32433887643676637011720 /Timeline/Services/JwtService.cs
parentfa468c3f6d9b9ba145b7bdb9f583b0fcc1f35713 (diff)
downloadtimeline-308c1faa5130913428b7348f78fe0fe2c406a63d.tar.gz
timeline-308c1faa5130913428b7348f78fe0fe2c406a63d.tar.bz2
timeline-308c1faa5130913428b7348f78fe0fe2c406a63d.zip
Add token expire time.
Diffstat (limited to 'Timeline/Services/JwtService.cs')
-rw-r--r--Timeline/Services/JwtService.cs8
1 files changed, 5 insertions, 3 deletions
diff --git a/Timeline/Services/JwtService.cs b/Timeline/Services/JwtService.cs
index f3416cce..52e892f6 100644
--- a/Timeline/Services/JwtService.cs
+++ b/Timeline/Services/JwtService.cs
@@ -94,10 +94,12 @@ namespace Timeline.Services
private readonly IOptionsMonitor<JwtConfig> _jwtConfig;
private readonly JwtSecurityTokenHandler _tokenHandler = new JwtSecurityTokenHandler();
+ private readonly IClock _clock;
- public JwtService(IOptionsMonitor<JwtConfig> jwtConfig)
+ public JwtService(IOptionsMonitor<JwtConfig> jwtConfig, IClock clock)
{
_jwtConfig = jwtConfig;
+ _clock = clock;
}
public string GenerateJwtToken(TokenInfo tokenInfo, DateTime? expires = null)
@@ -118,8 +120,8 @@ namespace Timeline.Services
Audience = config.Audience,
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.SigningKey)), SecurityAlgorithms.HmacSha384),
- IssuedAt = DateTime.Now,
- Expires = expires.GetValueOrDefault(DateTime.Now.AddSeconds(config.DefaultExpireOffset))
+ IssuedAt = _clock.GetCurrentTime(),
+ Expires = expires.GetValueOrDefault(_clock.GetCurrentTime().AddSeconds(config.DefaultExpireOffset))
};
var token = _tokenHandler.CreateToken(tokenDescriptor);