Unable to get it working. introduced ConfigureDataProtectionTokenProviderOptions, no DB Configured at time of execution...
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Models;
|
||||
using SZUAbsolventenverein.Module.AdminModules.Repository;
|
||||
|
||||
namespace SZUAbsolventenverein.Module.AdminModules.Server.Startup
|
||||
{
|
||||
public class ConfigureDataProtectionTokenProviderOptions : IConfigureOptions<DataProtectionTokenProviderOptions>
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public ConfigureDataProtectionTokenProviderOptions(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
Console.WriteLine("Instatiating DPTPO Configurator");
|
||||
}
|
||||
|
||||
public void Configure(DataProtectionTokenProviderOptions options)
|
||||
{
|
||||
Console.WriteLine("Configuring DPTPO");
|
||||
// default fallback
|
||||
options.TokenLifespan = TimeSpan.FromHours(2);
|
||||
|
||||
try
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var _dbContextFactory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<AdminModulesContext>>();
|
||||
var _ctx = _dbContextFactory.CreateDbContext();
|
||||
AdminSetting adminSetting = _ctx.AdminSettings.First();
|
||||
|
||||
Console.WriteLine("Setting DPTPO: " + adminSetting);
|
||||
if (adminSetting != null)
|
||||
{
|
||||
Console.WriteLine("Setting DPTPO: " + adminSetting.TokenLifetime);
|
||||
options.TokenLifespan = TimeSpan.FromDays(adminSetting.TokenLifetime);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("DB Not ready, using default DPTPO: " + ex);
|
||||
// DB not ready / read failed — keep default
|
||||
// Unable to get Create DB Context because Oqtane's Database Setup is incomplete.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user