BehaviorService fix
parent
19915f05d8
commit
a1a19da92a
|
@ -14,7 +14,7 @@ namespace IdentityServer.Application
|
||||||
services.AddSingleton<IConfigProvider, ConfigProvider>();
|
services.AddSingleton<IConfigProvider, ConfigProvider>();
|
||||||
services.AddSingleton<ITokenService, TokenService>();
|
services.AddSingleton<ITokenService, TokenService>();
|
||||||
services.AddScoped<IUserService, UserService>();
|
services.AddScoped<IUserService, UserService>();
|
||||||
services.AddScoped<IBehaviorService, BehaviorService>();
|
services.AddSingleton<IBehaviorService, BehaviorService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddStores(this IServiceCollection services)
|
private static void AddStores(this IServiceCollection services)
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
using IdentityServer.Application.Services.Abstractions;
|
using IdentityServer.Application.Services.Abstractions;
|
||||||
using IdentityServer.Application.Stores;
|
using IdentityServer.Application.Stores;
|
||||||
|
using IdentityServer.Domain.Entities;
|
||||||
using IdentityServer.Domain.Models;
|
using IdentityServer.Domain.Models;
|
||||||
using IdentityServer.Domain.Repositories;
|
using IdentityServer.Domain.Repositories;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace IdentityServer.Application.Services
|
namespace IdentityServer.Application.Services
|
||||||
{
|
{
|
||||||
internal class BehaviorService : IBehaviorService
|
internal class BehaviorService : IBehaviorService
|
||||||
{
|
{
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly ILogger<BehaviorService> _logger;
|
||||||
private readonly ITokenStore _securityStore;
|
private readonly ITokenStore _securityStore;
|
||||||
private readonly IIdentityRepository _identityRepository;
|
|
||||||
|
|
||||||
public BehaviorService(ITokenStore securityStore, IIdentityRepository identityRepository)
|
public BehaviorService(IServiceProvider serviceProvider, ILogger<BehaviorService> logger, ITokenStore securityStore)
|
||||||
{
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_logger = logger;
|
||||||
_securityStore = securityStore;
|
_securityStore = securityStore;
|
||||||
_identityRepository = identityRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillTokenStore()
|
public void FillTokenStore()
|
||||||
|
@ -22,10 +28,17 @@ namespace IdentityServer.Application.Services
|
||||||
|
|
||||||
public async Task FillTokenStoreAsync()
|
public async Task FillTokenStoreAsync()
|
||||||
{
|
{
|
||||||
var activeTokens = await _identityRepository.GetActiveTokens();
|
var activeTokens = Array.Empty<UserToken>();
|
||||||
|
using (var scope = _serviceProvider.CreateScope())
|
||||||
|
{
|
||||||
|
var _repository = scope.ServiceProvider.GetRequiredService<IIdentityRepository>();
|
||||||
|
activeTokens = await _repository.GetActiveTokens();
|
||||||
|
}
|
||||||
|
|
||||||
if (activeTokens.Length <= 0)
|
if (activeTokens.Length <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_logger.LogInformation($"BehaviorService: {activeTokens.Length} active tokens were found in database.");
|
||||||
foreach (var token in activeTokens)
|
foreach (var token in activeTokens)
|
||||||
{
|
{
|
||||||
var storeToken = new Token() { Raw = token.Token, ValidFrom = token.ValidFrom, ValidUntil = token.ValidUntil };
|
var storeToken = new Token() { Raw = token.Token, ValidFrom = token.ValidFrom, ValidUntil = token.ValidUntil };
|
||||||
|
|
Loading…
Reference in New Issue