I would recommend that you synchronize the session lifetime on STS and RP (s).
You can set the session lifetime to 10 minutes on the STS and 10 minutes on the RP and use the sliding session approach on the RP. After 10 minutes of inactivity, both sessions expire and the user will need to re-authenticate.
If you have multiple RPs, you can implement the keep-alive form from RP to STS - for example, load a resource from STS on each RP web page. Whenever a page is loaded onto an RP, the keep-alive resource will be loaded from STS - updating the STS session. After 10 minutes of inactivity, they both time out and the user will need to re-authenticate.
βResource from STSβ can mean a web page (Web Forms / MVC) loaded in an invisible iframe. The important thing is that this is a managed handler, so the request is processed by ASP.NET.
As for your questions, if you synchronize the session lifetime so that they are timing together:
- No, you do not need to add code to the else clause. If the token has expired, the WIF will be redirected to STS.
- Just remove the else clause.
- Let WIF handle this for you.
For completeness, if you cannot synchronize the session lifetime, you can start a federated exit when the RP session expires. The following snippet starts a statement from a configured issuer (STS). You can put this in an else clause to cause the first request to drop after the end of the RP session:
using System.IdentityModel.Services; //WIF 4.5 var stsAddress = new Uri(FederatedAuthentication.FederationConfiguration.WsFederationConfiguration.Issuer); WSFederationAuthenticationModule.FederatedSignOut(stsAddress, null); //Optional replyUrl set to null
Hope this helps!
source share