private async Task CheckForRefreshAsync(AuthenticationTicket ticket) { var currentUtc = Clock.UtcNow; var issuedUtc = ticket.Properties.IssuedUtc; var expiresUtc = ticket.Properties.ExpiresUtc; var allowRefresh = ticket.Properties.AllowRefresh ?? true; if (issuedUtc != null && expiresUtc != null && Options.SlidingExpiration && allowRefresh) { var timeElapsed = currentUtc.Subtract(issuedUtc.Value); var timeRemaining = expiresUtc.Value.Subtract(currentUtc); var eventContext = new CookieSlidingExpirationContext(Context, Scheme, Options, ticket, timeElapsed, timeRemaining) { ShouldRenew = timeRemaining < timeElapsed, }; await Options.Events.OnCheckSlidingExpiration(eventContext); if (eventContext.ShouldRenew) { RequestRefresh(ticket); } } }
/// <summary> /// Invoked to check if the cookie should be renewed. /// </summary> /// <param name="context">The <see cref="CookieSlidingExpirationContext"/>.</param> public virtual Task CheckSlidingExpiration(CookieSlidingExpirationContext context) => OnCheckSlidingExpiration(context);