title: Asp.net Core 2 with IdentityServer4 - Redirect to Login after cookie expiration
body: <p>I have an Asp.net Core 2.2 MVC application that authenticates using an IdentityServer4 server.
  It is configured as you can see on the bottom, with really short times for quick testing.</p>
  
  <p>The desired behavior is:</p>
  
  <ul>
  <li>Login (suppose without the "remember me checked")</li>
  <li>Do things...</li>
  <li>Wait until the session expires</li>
  <li>On the next navigation click redirect on the login page for a new interactive sign-in</li>
  </ul>
  
  <p>I supposed I must work on cookies and session server side, but my first doubt is that I have to work more with id_token.</p>
  
  <p>Anyway the current behavior is:</p>
  
  <ul>
  <li>Login without the "remember me checked"</li>
  <li>Wait until the session expires</li>
  <li>Click on a dummy page and I see that the session is empty (as expected) -> The login is available on the top menu</li>
  <li>So I click on login -> <strong>No login page showed</strong> -> a new session server side is available and in the browser there is a new value of ".AspNetCore.Cookies" but the same for ".AspNetCore.Identity.Application" and "idsrv.session".</li>
  </ul>
  
  <p>If I logout, the cookie client side is correctly removed, so at the next login shows the expected credential form.</p>
  
  <p>What I'm doing wrong? 
  Is it correct to try to get a new interactive sign-in checking the cookie expiration?
  Do I have to follow another way working on the ids (id_token) objects?</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddSingleton&lt;IConfiguration&gt;(Configuration);
  
      services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
      {
          options.MinimumSameSitePolicy = SameSiteMode.None;
      });
  
      JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
  
      services.AddAuthentication(options =&gt;
      {
          options.DefaultScheme = "Cookies";
          options.DefaultChallengeScheme = "oidc";
      })
      .AddCookie("Cookies", options =&gt;
      {
          options.SlidingExpiration = true;
          options.ExpireTimeSpan = TimeSpan.FromSeconds(30);
      })
      .AddOpenIdConnect("oidc", options =&gt;
      {
          options.SignInScheme = "Cookies";
          options.Authority = Configuration.GetValue&lt;string&gt;("IdentitySettings:Authority");
          options.RequireHttpsMetadata = false;
  
          options.ClientId = "mvc";
          options.SaveTokens = true;
  
          options.Events.OnTicketReceived = async (context) =&gt;
          {
              context.Properties.ExpiresUtc = DateTime.UtcNow.AddSeconds(30);
          };
      });
  
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment() || env.IsStaging())
      {
          app.UseDeveloperExceptionPage();
      }
      else
      {
          app.UseExceptionHandler("/Error");
      }
  
      app.UseAuthentication();
  
      app.UseStaticFiles();
      app.UseCookiePolicy();
  
      app.UseMvc(routes =&gt;
      {
          routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}/{id?}");
      });
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>The logout is done as following</p>
  
  <pre><code>public async void OnPost()
  {
      await HttpContext.SignOutAsync("Cookies");
  
      await HttpContext.SignOutAsync("oidc",
          new AuthenticationProperties
          {
              RedirectUri = "http://localhost:5002"
          });
  }
  </code></pre>