public static HttpCookie RecreateAuthenticationCookie(this FormsAuthenticationTicket existing, CustomPrincipalInfo newInfo, DateTime current) { var info = existing.GetCustomPrincipalInfo(); info.Update(newInfo); var timeout = existing.Expiration - existing.IssueDate; return CreateAuthenticationCookie(info, current, timeout.Minutes, existing.IsPersistent); }
public void UpdateUserCookiesInfo(CustomPrincipalInfo info) { // TODO: Move the dependency to an external service or to the consumer var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; var ticket = cookie.GetFormsAuthenticationTicket(); var updated = ticket.RecreateAuthenticationCookie(info, DateTime.Now); HttpContext.Current.Response.Cookies.Add(updated); }
public static void Update(this CustomPrincipalInfo current, CustomPrincipalInfo newInfo) { current.UserId = newInfo.UserId; current.Email = newInfo.Email; }
protected virtual void ProcessAuthCookiesPayload(HttpApplication application, CustomPrincipalInfo principalInfo) { application.Context.User = (CustomPrincipal)principalInfo; }