tuitio/IdentityServer.Application/Services/BehaviorService.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2021-11-13 17:17:13 +02:00
using IdentityServer.Application.Services.Abstractions;
using IdentityServer.Application.Stores;
using IdentityServer.Domain.Models;
using IdentityServer.Domain.Repositories;
using System.Threading.Tasks;
namespace IdentityServer.Application.Services
{
internal class BehaviorService : IBehaviorService
{
private readonly ITokenStore _securityStore;
private readonly IIdentityRepository _identityRepository;
public BehaviorService(ITokenStore securityStore, IIdentityRepository identityRepository)
{
_securityStore = securityStore;
_identityRepository = identityRepository;
}
public void FillTokenStore()
=> FillTokenStoreAsync().GetAwaiter().GetResult();
public async Task FillTokenStoreAsync()
{
var activeTokens = await _identityRepository.GetActiveTokens();
if (activeTokens.Length <= 0)
return;
foreach (var token in activeTokens)
{
var storeToken = new Token() { Raw = token.Token, ValidFrom = token.ValidFrom, ValidUntil = token.ValidUntil };
_securityStore.SetToken(storeToken, token.UserId);
}
}
}
}