This project has moved. For the latest updates, please go here.

AuthenticationProperties.ExpireUtc property ignored in Owin CookieAuthentication?

Jun 26, 2014 at 5:08 PM
Edited Jun 26, 2014 at 5:18 PM
Hi,

I have been doing some testing after converting my MVC 4 web application to MVC 5 and Owin authentication.
I have a facility where the user can select their login duration (session, 1 day, 10 days, etc) which worked well with Forms authentication, but which does not work at all with Owin CookieAuthentication.
I have tested with my app as well as the standard MVC 5 Application template in VS2013.

From what I can tell you can provide a global override using the CookieAuthenticationOptions.ExpireTimeSpan, which works, but the AuthenticationProperties.ExpireUtc property that can be supplied during AuthenticationManager.SignIn() is ignored.


I then reviewed the Microsoft.Owin.Security.Cookies source and found that global override in the CookieAuthenticationHandler.ApplyResponseGrantAsync() method:
  • the AuthenticationProperties are loaded into the CookieResponseSignInContext instance; but
  • context.Properties.ExpireUtc is then immediately overwritten to Options.ExpireTimeSpan.
I tested the above and found that when I change:
DateTimeOffset expiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
to
DateTimeOffset expiresUtc = signin.Properties.ExpiresUtc ?? issuedUtc.Add(Options.ExpireTimeSpan);
it allows for the on-request implementation of AuthenticationProperties.ExpireUtc.


Can you please comment on:
  • whether you are seeing the same behaviour; and
  • which behaviour is the desired one (favour global ExpireTimeSpan or per-request ExpireUtc)?
Thanks.
Jun 26, 2014 at 5:55 PM
Edited Jun 26, 2014 at 5:59 PM
Hey ;)

Which version are you using?
This bug has been fixed in April: https://katanaproject.codeplex.com/SourceControl/changeset/a2c810d30a2946b2e064091e013781e56016df94
Coordinator
Jun 26, 2014 at 5:58 PM
I'm pretty sure I've already fixed this in v3. Take a look at the sources in the dev branch, and try the pre-release packages from here:
https://www.myget.org/f/aspnetwebstacknightly/

https://katanaproject.codeplex.com/SourceControl/changeset/a2c810d30a2946b2e064091e013781e56016df94
Jun 26, 2014 at 6:23 PM
Hi Tratcher and PinpointTownes,

Thanks for your speedy response.

I saw Issue / work item #115 from April and then grabbed 3.0.0-beta1 (e7538b488c13) on NuGet and the same source in error.
Apologies for the error and the effort...

I'll try those updated pre-release packages as you recommend, Thanks.