@@ -12,19 +12,19 @@ public class SubmitTokenService : ISubmitTokenService
12
12
{
13
13
private readonly IHttpContextAccessor _httpContextAccessor ;
14
14
private readonly IMemoryCache _memoryCache ;
15
-
16
- private readonly byte [ ] _key ;
15
+ private readonly ILogger < SubmitTokenService > _logger ;
16
+ private readonly byte [ ] _key ;
17
17
private readonly byte [ ] _iv ;
18
18
19
- public SubmitTokenService ( IHttpContextAccessor httpContextAccessor , IMemoryCache memoryCache )
19
+ public SubmitTokenService ( IHttpContextAccessor httpContextAccessor , IMemoryCache memoryCache , ILogger < SubmitTokenService > logger )
20
20
{
21
21
_httpContextAccessor = httpContextAccessor ;
22
22
_memoryCache = memoryCache ;
23
+ _logger = logger ;
23
24
24
-
25
- // Create a new DES object to generate a random _key
26
- // and initialization vector (IV).
27
- using ( DES des = DES . Create ( ) )
25
+ // Create a new DES object to generate a random _key
26
+ // and initialization vector (IV).
27
+ using ( DES des = DES . Create ( ) )
28
28
{
29
29
_key = des . Key ;
30
30
_iv = des . IV ;
@@ -73,6 +73,8 @@ public bool Validate(JwtPayload token, out TimeSpan? retryAfter)
73
73
{
74
74
var ipAddress = _httpContextAccessor . HttpContext . Connection . RemoteIpAddress . ToString ( ) ;
75
75
76
+ _logger . LogInformation ( $ "Ip { ipAddress } requested a new Token.") ;
77
+
76
78
var cacheKey = "ip-token-" + ipAddress ;
77
79
if ( _memoryCache . TryGetValue < TokenStore > ( cacheKey , out var tokenStore )
78
80
&& tokenStore . JwtPayload . ValidTo > DateTime . UtcNow )
@@ -85,7 +87,7 @@ public bool Validate(JwtPayload token, out TimeSpan? retryAfter)
85
87
return ( Encrypt ( tokenStore . JwtPayload ) , null ) ;
86
88
}
87
89
88
- var expiresAt = DateTime . UtcNow . AddHours ( 10 ) ;
90
+ var expiresAt = DateTime . UtcNow . AddHours ( 4 ) ;
89
91
tokenStore = new TokenStore ( ) ;
90
92
tokenStore . JwtPayload = new JwtPayload ( "jhwa/server" , "jhwa/client" , [ new Claim ( "ip" , ipAddress ) ] ,
91
93
DateTime . UtcNow , expiresAt , DateTime . UtcNow ) ;
0 commit comments