Сбой балансировки нагрузки сервера идентификации. Не работает, когда запущено несколько экземпляров сервера идентификации. С одним экземпляром сервера идентификации, он работает нормально, как и ожидалось.Это потому, что моя реализация IdentityServer4 не сохраняет маркер обновления?
Изначально на моем сервере идентификации было все в памяти store.now, что после сбоя балансировки нагрузки сервера Identity попытался реализовать IPersistantGrantStore и добавить AddOperationalStore, он создает БД.Но там ничего не хранится. Startup.cs ниже. Исправьте меня, если что-то не так.
public void ConfigureServices(IServiceCollection services)
{
ApplicationSettings applicationSettings = Configuration
.GetSection("ApplicationSettings")
.Get<ApplicationSettings>();
DatabaseSettings dbSettings = Configuration
.GetSection("DatabaseSettings")
.Get<DatabaseSettings>() ?? new DatabaseSettings();
LoggingSettings loggingSettings = Configuration
.GetSection("LoggingSettings")
.Get<LoggingSettings>();
var migrationsAssembly = this.GetType().Assembly.GetName().Name;
services.AddMvc();
services.InitialiseDbContext<PersistedGrantDbContext>(dbSettings);
var appSettingsSection = Configuration.GetSection("ApplicationSettings");
var appSettings = appSettingsSection.Get<ApplicationSettings>();
services.Configure<ApplicationSettings>(appSettingsSection);
.
services.AddCors(options =>
{
options.AddPolicy("AllowAllOriginsHeadersAndMethods",
builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
});
var identityServerBuilder = services
.AddIdentityServer(iso =>
{
if (String.IsNullOrEmpty(applicationSettings.PublicOriginUri) == false)
iso.PublicOrigin = applicationSettings.PublicOriginUri;
if (String.IsNullOrEmpty(applicationSettings.IssuerUri) == false)
iso.IssuerUri = applicationSettings.IssuerUri;
if (String.IsNullOrEmpty(applicationSettings.LoginUrl) == false)
iso.UserInteraction.LoginUrl = applicationSettings.LoginUrl;
});
if (CurrentEnvironment.IsDevelopment())
{
identityServerBuilder.AddDeveloperSigningCredential();
}
else
{
identityServerBuilder.AddSigningCredential(new CertificateManager().GetCertificate(applicationSettings.CertificateKey, applicationSettings.CertificatePrivateKey,
applicationSettings.CertificatePassword, string.Empty, string.Empty, applicationSettings.AWSEndPointRegion));
}
// this adds the operational data from DB (codes, tokens, consents)
identityServerBuilder.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseNpgsql(dbSettings.ConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
// this enables automatic token cleanup. this is optional.
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 10; // interval in seconds, short for testing
});
services.AddSingleton<IUserFacade, UserFacade>();
services.AddTransient<IProfileService, ProfileService>();
// Setup dependency injection (TODO: Replace the 'InMemoryXxxxx' services with real ones):
services.AddScoped<IConfigurationFacade, InMemoryConfigurationFacade>();
services.AddSingleton<IClientStore, JsonFileClientStore>();
services.AddSingleton<IResourceStore, ResourcesStore>();
services.AddScoped<IHttpContextFacade, HttpContextFacade>();
services.AddScoped<IUserContextFacade, UserContextFacade>();
services.AddSingleton<IRestHelper, RestHelper>();
services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
services.AddHttpClient();
ServiceProvider serviceProvider = services.BuildServiceProvider();
IConfigurationFacade config = serviceProvider.GetService<IConfigurationFacade>();
services
.AddAuthentication(IdentityServerCookieName)
.AddCookie(IdentityServerCookieName, options =>
{
options.ExpireTimeSpan = config.UserCookieInactiveLife();
});
}
private void InitializeDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetRequiredService<PersistedGrantDbContext>().Database.Migrate();
//TODO-uncomment the below while enabling identityServerBuilder.AddConfigurationStore
//var context = serviceScope.ServiceProvider.GetRequiredService<ConfigurationDbContext>();
//context.Database.Migrate();
}
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
InitializeDatabase(app);
app.UseCors("AllowAllOriginsHeadersAndMethods");
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
Необходимо устранить ошибку балансировки нагрузки Identity Server