37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|