/// <summary> /// Creates the umbraco authentication ticket /// </summary> /// <param name="http"></param> /// <param name="userdata"></param> public static void CreateUmbracoAuthTicket(this HttpContextBase http, UserData userdata) { CreateAuthTicket( http, userdata, //This is one full day... this is how Umbraco has always created this cookie, it is setup to always //expire one day from issue and it never gets updated. 1440, "/", UmbracoSettings.AuthCookieName, UmbracoSettings.AuthCookieDomain); }
/// <summary> /// This will ensure we only deserialize once /// </summary> /// <remarks> /// For performance reasons, we'll also check if there's an http context available, /// if so, we'll chuck our instance in there so that we only deserialize once per request. /// </remarks> protected void EnsureDeserialized() { if (DeserializedData != null) return; if (HttpContext.Current != null) { //check if we've already done this in this request var data = HttpContext.Current.Items[typeof(UmbracoBackOfficeIdentity)] as UserData; if (data != null) { DeserializedData = data; return; } } if (string.IsNullOrEmpty(UserData)) { throw new NullReferenceException("The " + typeof(UserData) + " found in the ticket cannot be empty"); } DeserializedData = JsonConvert.DeserializeObject<UserData>(UserData); if (HttpContext.Current != null) { HttpContext.Current.Items[typeof (UmbracoBackOfficeIdentity)] = DeserializedData; } }
internal static void CreateUmbracoAuthTicket(this HttpContext http, UserData userdata) { new HttpContextWrapper(http).CreateUmbracoAuthTicket(userdata); }
/// <summary> /// Creates a custom umbraco auth cookie with the data specified /// </summary> /// <param name="http">The HTTP.</param> /// <param name="userData">The user data.</param> /// <param name="minutesPersisted">The minutes persisted.</param> /// <param name="cookiePath">The cookie path.</param> /// <param name="cookieName">Name of the cookie.</param> /// <param name="cookieDomain">The cookie domain.</param> private static void CreateAuthTicket(this HttpContextBase http, UserData userData, int minutesPersisted, string cookiePath, string cookieName, string cookieDomain) { var cookie = new HttpCookie(cookieName); if (GlobalSettings.UseSSL) cookie.Secure = true; //ensure http only, this should only be able to be accessed via the server cookie.HttpOnly = true; cookie.Path = cookiePath; cookie.Domain = cookieDomain; cookie.Expires = DateTime.Now.AddMinutes(minutesPersisted); //serialize the user data var json = JsonConvert.SerializeObject(userData); //encrypt it var encTicket = json.EncryptWithMachineKey(); //set the cookie value cookie.Value = encTicket; http.Response.Cookies.Set(cookie); }
internal static FormsAuthenticationTicket CreateUmbracoAuthTicket(this HttpContext http, UserData userdata) { if (http == null) { throw new ArgumentNullException("http"); } if (userdata == null) { throw new ArgumentNullException("userdata"); } return(new HttpContextWrapper(http).CreateUmbracoAuthTicket(userdata)); }
/// <summary> /// Creates the umbraco authentication ticket /// </summary> /// <param name="http"></param> /// <param name="userdata"></param> public static FormsAuthenticationTicket CreateUmbracoAuthTicket(this HttpContextBase http, UserData userdata) { if (http == null) { throw new ArgumentNullException("http"); } if (userdata == null) { throw new ArgumentNullException("userdata"); } var userDataString = JsonConvert.SerializeObject(userdata); return(CreateAuthTicketAndCookie( http, userdata.Username, userDataString, //use the configuration timeout - this is the same timeout that will be used when renewing the ticket. GlobalSettings.TimeOutInMinutes, //Umbraco has always persisted it's original cookie for 1 day so we'll keep it that way 1440, UmbracoConfig.For.UmbracoSettings().Security.AuthCookieName, UmbracoConfig.For.UmbracoSettings().Security.AuthCookieDomain)); }
internal static FormsAuthenticationTicket CreateUmbracoAuthTicket(this HttpContext http, UserData userdata) { if (http == null) throw new ArgumentNullException("http"); if (userdata == null) throw new ArgumentNullException("userdata"); return new HttpContextWrapper(http).CreateUmbracoAuthTicket(userdata); }
/// <summary> /// Creates the umbraco authentication ticket /// </summary> /// <param name="http"></param> /// <param name="userdata"></param> public static FormsAuthenticationTicket CreateUmbracoAuthTicket(this HttpContextBase http, UserData userdata) { if (http == null) throw new ArgumentNullException("http"); if (userdata == null) throw new ArgumentNullException("userdata"); var userDataString = JsonConvert.SerializeObject(userdata); return CreateAuthTicketAndCookie( http, userdata.Username, userDataString, //use the configuration timeout - this is the same timeout that will be used when renewing the ticket. GlobalSettings.TimeOutInMinutes, //Umbraco has always persisted it's original cookie for 1 day so we'll keep it that way 1440, "/", UmbracoConfig.For.UmbracoSettings().Security.AuthCookieName, UmbracoConfig.For.UmbracoSettings().Security.AuthCookieDomain); }