void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { string encTicket = authCookie.Value; if (!String.IsNullOrEmpty(encTicket)) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encTicket); OpenIdIdentity id = new OpenIdIdentity(ticket); GenericPrincipal principal = new GenericPrincipal(id, null); HttpContext.Current.User = principal; } } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var isAuthorized = base.AuthorizeCore(httpContext); if (isAuthorized) { var authenticatedCookie = httpContext.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authenticatedCookie != null) { var authenticatedCookieValue = authenticatedCookie.Value.ToString(); if (!string.IsNullOrWhiteSpace(authenticatedCookieValue)) { var decryptedTicket = FormsAuthentication.Decrypt(authenticatedCookieValue); var user = new OpenIdUser(decryptedTicket.UserData); var openIdIdentity = new OpenIdIdentity(user); httpContext.User = new GenericPrincipal(openIdIdentity, null); } } } return isAuthorized; }