IdentityServer4丢失登录会话

时间:2018-05-17 17:21:38

标签: oauth-2.0 openid identityserver4

我将IdentityServer4放在azure上并且工作正常,但是当我登录到IdentityServer4时,它只会保持登录状态大约20分钟,然后再次请求登录(重定向到登录屏幕)。

有人知道如何只登录一次吗?

 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);
            });


    }

1 个答案:

答案 0 :(得分:0)

这不是魔术,它只是使用cookie。最可能的是您的身份验证cookie的生命周期。如果它默认为20分钟,我不会感到惊讶。