source: FarmatikoServices/Infrastructure/JwtRefreshTokenCache.cs@ 8e74e2f

Last change on this file since 8e74e2f was d23bf72, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Add SystemService, Auth, fix a lil bugs :)

  • Property mode set to 100644
File size: 1.1 KB
Line 
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4using FarmatikoServices.Infrastructure;
5using Microsoft.Extensions.Hosting;
6
7namespace FarmatikoServices.Infrastructure
8{
9 public class JwtRefreshTokenCache : IHostedService, IDisposable
10 {
11 private Timer _timer;
12 private readonly IJwtAuthManager _jwtAuthManager;
13
14 public JwtRefreshTokenCache(IJwtAuthManager jwtAuthManager)
15 {
16 _jwtAuthManager = jwtAuthManager;
17 }
18
19 public Task StartAsync(CancellationToken stoppingToken)
20 {
21 // remove expired refresh tokens from cache every minute
22 _timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
23 return Task.CompletedTask;
24 }
25
26 private void DoWork(object state)
27 {
28 _jwtAuthManager.RemoveExpiredRefreshTokens(DateTime.Now);
29 }
30
31 public Task StopAsync(CancellationToken stoppingToken)
32 {
33 _timer?.Change(Timeout.Infinite, 0);
34 return Task.CompletedTask;
35 }
36
37 public void Dispose()
38 {
39 _timer?.Dispose();
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.