title: TankAuth Session expire feature invalidating my Delphi Desktop Application
body: <p>I have a desktop app (developed with <strong>Delphi XE2</strong>) that login &amp; interacts with a <strong>PHP 5</strong> web application (I use <strong>CodeIgniter 2.1</strong> along with <strong><a href="https://github.com/ilkon/Tank-Auth" rel="nofollow">TankAuth</a></strong> - both latest version)</p>
  
  <p>It seems that <strong>TankAuth has a session expire</strong> feature (that kicks in <strong>every 5 minutes</strong>) to prevent session hijacking. It's a good security measure, but...</p>
  
  <p>This also <strong>invalidate the Delphi application login</strong>. More specifically, I need to update cookies (<strong>I use Indy 10.4861</strong>), which means <strong>I have to re-login every 5 minutes</strong></p>
  
  <p>My Delphi XE2 application uses multi-threading. I use a global cookie (to avoid logging in every thread!), so I have to resolve to lock every 5 minutes to re-login.</p>
  
  <p>My profiler clearly says I need to do something about it!</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>TheResponse   := TStringStream.Create;
  try
     IdHttp.Get(TheURL, TheResponse);
  
     if (TheResponse &lt;&gt; nil) And (Pos('login', TheResponse.DataString) &lt;&gt; 0) then
     begin
          OmniLock.Acquire;
          try
             LoginToServer(ServerLogin, UserPassword);
          finally
                 OmniLock.Release;
          end;    // try/finally
  
          // Reload local copie of the cookies manager
          OmniLock.Acquire;
          try
             TheCookieManager.AddCookies(GlobalCookieManager);
          finally
                 OmniLock.Release;
          end;    // try/finally
  except
        // ...
  end;    // try/except
  </code></pre>
  
  <p><strong>My question is:</strong> Is there a way to keep the session expire, but somehow capture the changed session expire and update the cookie manager <strong>without</strong> having to re-login?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>The global cookie manager gets updated whenever there's a new cookie:</p>
  
  <pre><code>idHTTP.OnNewCookie := SyncNewCookie;
  
  // ------------------------------------------------------------------------------ //
  procedure TMainForm.SyncNewCookie(ASender : TObject; ACookie : TIdCookie; var VAccept : Boolean);
  begin
       VAccept := True;
  
       OmniLock.Acquire;
       try
          GlobalCookieManager.CookieCollection.AddServerCookie(ACookie.ServerCookie, TIdHTTP(TIdCookieManager(ASender).Owner).URL);
       finally
              OmniLock.Release;
       end;    // try/finally
  end;
  </code></pre>