I am experiencing a problem with a login loop when using WsFederation Authentication in my MVC web application. I used visual studio to create the scaffolding of the web application and to setup the WsFederation in the Startup.cs. Which generates the following block of code:
public class Startup
{
    private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
    private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
    public void Configuration(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
        {
            Wtrealm = realm,
            MetadataAddress = adfsMetadata
        });
    }
}
The web application is hosted in Azure and the ADFS is on premises.
On some clients, when a login attempt is made the login page goes into a loop requesting a new tokens causing the following exception on the ADFS Server:
Exception details: Microsoft.IdentityServer.Web.InvalidRequestException: MSIS7042: The same client browser session has made '6' requests in the last '7' seconds. Contact your administrator for details.
I have read many articles on StackOverflow and looked at the various examples provided by the guys who wrote IdentityServer and I have tried the various configuration options and I cannot isolate the problem to a specific area.
From what I read it is a general problem with the OWIN middle ware loosing context of the object and as a result the token gets "lost".
I have attempted to implement some of the sample code that other have provided on StackOverflow but, I cannot seem to find a solution the resolves my problem or maybe a have not implemented the code correctly.
Any Ideas?
 
    