From cc6784b0730c1f50959acd3ebc658a8e97cd35f1 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 24 Dec 2020 04:55:45 +0200 Subject: [PATCH] token store fix --- IdentityServer.Application/Services/UserService.cs | 4 ++-- IdentityServer.Application/Stores/ISecurityStore.cs | 2 +- IdentityServer.Application/Stores/SecurityStore.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/IdentityServer.Application/Services/UserService.cs b/IdentityServer.Application/Services/UserService.cs index 7225d2c..3c7aa88 100644 --- a/IdentityServer.Application/Services/UserService.cs +++ b/IdentityServer.Application/Services/UserService.cs @@ -25,9 +25,9 @@ namespace IdentityServer.Application.Services return null; var tokenRaw = $"{Guid.NewGuid()}-{Guid.NewGuid()}-{user.UserId}"; - _securityStore.SetToken(tokenRaw, user.UserId); + var token = new Token() { Raw = tokenRaw, ValidUntil = DateTime.Now.AddMonths(12) }; + _securityStore.SetToken(token, user.UserId); - var token = new Token() { Raw = tokenRaw }; return token; } diff --git a/IdentityServer.Application/Stores/ISecurityStore.cs b/IdentityServer.Application/Stores/ISecurityStore.cs index a9e8cc5..c46ef8f 100644 --- a/IdentityServer.Application/Stores/ISecurityStore.cs +++ b/IdentityServer.Application/Stores/ISecurityStore.cs @@ -4,7 +4,7 @@ namespace IdentityServer.Application.Stores { public interface ISecurityStore { - void SetToken(string token, int userId); + void SetToken(Token token, int userId); TokenValidation ValidateToken(string token); } } diff --git a/IdentityServer.Application/Stores/SecurityStore.cs b/IdentityServer.Application/Stores/SecurityStore.cs index 6cd8901..6daba27 100644 --- a/IdentityServer.Application/Stores/SecurityStore.cs +++ b/IdentityServer.Application/Stores/SecurityStore.cs @@ -15,14 +15,14 @@ namespace IdentityServer.Application.Stores Tokens = new ConcurrentDictionary>(); } - public void SetToken(string token, int userId) + public void SetToken(Token token, int userId) { var registered = Tokens.TryGetValue(userId, out List list); if (registered) - list.Add(new Token() { Raw = token }); + list.Add(token); else - Tokens.TryAdd(userId, new List() { new Token() { Raw = token } }); + Tokens.TryAdd(userId, new List() { token }); } public TokenValidation ValidateToken(string token)