I am using IdentityServer3 for authentication and I have ASP.NET MVC application as Client. I want to setup sliding expiration of authentication cookie.
So as long as user is actively doing something in client application he should be logged in. If he remains inactive (with browser open) for more than 120 mins and then try to use client application then he should get redirected to log in page.
There are bunch of settings related to sliding expiration In IdentityServer3's IdentityServerOptions
and also in client application's CookieAuthenticationOptions
and OpenIdConnectAuthenticationOptions
On Identity Server i have the following configuration
app.Map("/identity", idsrvApp =>
{
idsrvApp.UseIdentityServer(new IdentityServerOptions
{
SiteName = "Login",
SigningCertificate = LoadCertificate(),
RequireSsl = true,
Factory = new IdentityServerServiceFactory()
.Configure(),
AuthenticationOptions = new AuthenticationOptions()
{
CookieOptions = new CookieOptions()
{
AllowRememberMe = false,
SlidingExpiration = true
}
}
.Configure(ConfigureIdentityProviders),
EventsOptions = new EventsOptions().Configure(),
EnableWelcomePage = ApplicationConfig.EnableWelcomePage
});
});
}
I have set the Client.IdentityTokenLifetime
to 7200
seconds
In client application i have the following configuration
var cookieOptions = new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
LoginPath = new Microsoft.Owin.PathString("/Home"),
SlidingExpiration = true
};
var openIdOptions = new OpenIdConnectAuthenticationOptions
{
Authority = ConfigurationManager.AppSettings["id:Authority"],
Scope = "openid email profile",
ClientId = "XXXXXXXXX",
RedirectUri = "http://localhost/Home",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies",
UseTokenLifetime = true,
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = (context) =>
{
// do something
},
RedirectToIdentityProvider = (context) =>
{
// do something
},
AuthenticationFailed = context =>
{
// do something
}
}
};
app.UseCookieAuthentication(cookieOptions);
app.UseOpenIdConnectAuthentication(openIdOptions);
Note that i have set UseTokenLifetime
to true
so the cookie timeout will aligned with Client.IdentityTokenLifetime
ISSUE Even if the user is active for 120 mins, He gets logged out exactly after 120 mins.
What else i need to do enable sliding expiration?
(I have already gone through several post on SO and also IdentityServer's forum but no one has concrete answer)