title: ADFS freshness and session sliding
body: <pre><code>I have implemented session sliding using in my customehttphandler module.
  </code></pre>
  
  <p>I am trying to acheive session sliding as well as getting authenticated on multiple website which share same ADFS server.</p>
  
  <pre><code> public void SessionAuthenticationModuleSessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e)
          {
              SessionSecurityToken token = e.SessionToken;
              DateTime nowUtc = DateTime.UtcNow;
              DateTime validFrom = token.ValidFrom;
              DateTime validTo = token.ValidTo;
              double totalMinutes = (validTo - validFrom).TotalMinutes;
              double halfSpan = totalMinutes / 2;
  
              SessionAuthenticationModule sam = sender as SessionAuthenticationModule;
  
              if (validTo &lt; nowUtc)
              {
                  if (sam != null)
                  {
                      sam.DeleteSessionTokenCookie();
                      e.Cancel = true;
                  }               
              }
              else if ((nowUtc - validFrom).TotalMinutes &gt;= halfSpan)
              {
                  SessionSecurityToken renewToken =             sam.CreateSessionSecurityToken(
                      token.ClaimsPrincipal,
                      token.Context,
                      nowUtc,
                      nowUtc.AddMinutes(totalMinutes),
                      true);
                  e.SessionToken = renewToken;
  
                  e.ReissueCookie = true;
  
  //db timestamp update
              }
          }
  
  And SignedIn event
  
   public void WSFederationAuthenticationModuleSignedIn(object sender, EventArgs e)
          {
  
               token = gettoken from cookie
              if (token.ValidTo &gt; DateTime.Now.ToUniversalTime())
              {
                       //db insert for new login (assuming this will fire only      once on actual login)
                     reissue token
              }
         }
  
  Session timeout is mentioned in the my relying party application web config
  
  &lt;securityTokenHandlers&gt;
          &lt;add type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt;
            &lt;sessionTokenRequirement lifetime="0:02" /&gt;
          &lt;/add&gt;
        &lt;/securityTokenHandlers&gt;
  
  Token Life time on ADFS I do not want to change which is greater than 2 minutes.
  
  But issue is, after 2 minutes time out is not happening. It goes to SingedIn event becuase i assume it reissue token and then it calls session token received event so this condition (if (validTo &lt; nowUtc)) never satisfy, how can i achieve timeout here? Freshness="0"achieves it but If i set Freshness="0" then I can not get authenticated by other website which are on same ADFS server. I want to be authenticated on other website as well if i have logged in one.
  
  If I remove freshness="0" I can be authenticated without login on second website which is different application.
  
  Why SignedIn is getting called before session token received and How can i achieve timeout in proper way and get authenticated in multiple website?
  </code></pre>
  
  <p>Note: I have these events in my customeHttpHanlder module. which has other event as well like PostAuthenticateRequest.</p>