Oauth 2.0 IdentityServer 4丢失登录会话
我将IdentityServer4放在azure上,它工作正常,但当我登录到IdentityServer4时,它只会保持登录状态大约20分钟,然后再次请求登录(重定向到登录屏幕) 有人知道如何只登录一次吗Oauth 2.0 IdentityServer 4丢失登录会话,oauth-2.0,openid,identityserver4,Oauth 2.0,Openid,Identityserver4,我将IdentityServer4放在azure上,它工作正常,但当我登录到IdentityServer4时,它只会保持登录状态大约20分钟,然后再次请求登录(重定向到登录屏幕) 有人知道如何只登录一次吗 public void ConfigureServices(IServiceCollection services) { services.AddMvc(op => op.Filters.Add(new AuthorizeAttributeFilter()));
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(op => op.Filters.Add(new AuthorizeAttributeFilter()));
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentity<ApplicationUser, IdentityRole>(option =>
{
option.Password.RequireDigit = false;
option.Password.RequiredLength = 3;
option.Password.RequiredUniqueChars = 0;
option.Password.RequireLowercase = false;
option.Password.RequireNonAlphanumeric = false;
option.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseSuccessEvents = true;
options.Authentication.CookieLifetime = TimeSpan.FromHours(24);
options.Authentication.CookieSlidingExpiration = true;
})
.AddDeveloperSigningCredential()
.AddAspNetIdentity<ApplicationUser>()
.AddClientStore<ClientStore>()
.AddProfileService<ProfileService>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
db => db.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
db => db.MigrationsAssembly(migrationsAssembly));
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddAuthentication("MyCookie")
.AddCookie("MyCookie", options =>
{
options.ExpireTimeSpan = TimeSpan.FromHours(24);
});
}
public void配置服务(IServiceCollection服务)
{
services.AddMvc(op=>op.Filters.Add(newauthorizeAttributeFilter());
var migrationassembly=typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
服务。附加性(选项=>
{
option.Password.RequireDigit=false;
option.Password.RequiredLength=3;
option.Password.RequiredUniqueChars=0;
option.Password.RequireLowercase=false;
option.Password.RequireNonAlphanumeric=false;
option.Password.RequireUppercase=false;
})
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.AddIdentityServer(选项=>
{
options.Events.RaiseErrorEvents=true;
options.Events.RaiseFailureEvents=true;
options.Events.RaiseInformationEvents=true;
options.Events.RaiseSuccessEvents=true;
options.Authentication.CookieLifetime=TimeSpan.FromHours(24);
options.Authentication.CookieSlidingExpiration=true;
})
.AddDeveloperSigningCredential()
.AddAsNetIdentity()
.AddClientStore()
.AddProfileService()
.AddConfigurationStore(选项=>
{
options.ConfigureDbContext=builder=>
builder.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”),
db=>db.migrationassembly(migrationassembly));
})
.addStore(选项=>
{
options.ConfigureDbContext=builder=>
builder.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”),
db=>db.migrationassembly(migrationassembly));
});
services.AddDbContext(选项=>
options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
services.AddAuthentication(“mycokie”)
.AddCookie(“MyCookie”,选项=>
{
options.ExpireTimeSpan=TimeSpan.FromHours(24);
});
}
这不是魔法,只是用了一块饼干。最可能的情况是验证cookie的生存期。如果它默认为20分钟,我不会感到惊讶 您需要检查IS4日志以找出您的身份验证会话被删除的原因。@AlexBuyny好的,我将配置Serilog以检查发生了什么。tksI设置了30天的所有超时,但我仍然没有成功验证cookie的有效期是多少?