Esempio n. 1
0
        //After authentication, if successful, perform authorization
        void context_PostAuthenticateRequest(object sender, EventArgs e)
        {
            //Disregard backoffice requests:
            //TODO. Use GlobalSettings.RequestIsInUmbracoApplication(HttpContext.Current)!!
            if (UmbracoContext.Current == null || UmbracoContext.Current.HttpContext.Request.Url.AbsolutePath.StartsWith("/umbraco") || UmbracoContext.Current.HttpContext.Request.Url.AbsolutePath.StartsWith("/ScriptResource.axd")) //NOT WORKING!!!UmbracoContext.Current.IsFrontEndUmbracoRequest)
            {
                return;
            }

            HttpContext context = (sender as HttpApplication).Context;

            HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                //Extract the forms authentication cookie
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

                // If caching roles in userData field then extract
                FacebookPrincipalSerializableModel model = new JavaScriptSerializer().Deserialize <FacebookPrincipalSerializableModel>(authTicket.UserData);

                //Search roles: TODO: implement with mail address
                MembershipUser mUser = null;
                string[]       roles = null;

                mUser = Authorize(model, out roles);

                // Create the IPrinciple instance
                IPrincipal principal = new FacebookPrincipal(model.UniqueLink, roles)
                {
                    FirstName      = model.FirstName,
                    UserName       = model.UserName,
                    FacebookId     = model.FacebookId,
                    AccessToken    = model.AccessToken,
                    UniqueLink     = model.UniqueLink,
                    EMail          = model.EMail,
                    MembershipUser = mUser
                };

                // Set the context user
                context.User = principal;

                if (principal.IsInRole("Triphulcas"))
                {
                    //if (String.IsNullOrEmpty(umbraco.BasePages.BasePage.umbracoUserContextID))
                    if (umbraco.BasePages.UmbracoEnsuredPage.CurrentUser == null)
                    {
                        // Hack. Set the Umbraco backoffice related user as logged - in
                        umbraco.BasePages.BasePage.doLogin(new User("triphulca"));
                    }
                }
            }
        }
        //After authentication, if successful, perform authorization
        void context_PostAuthenticateRequest(object sender, EventArgs e)
        {
            //Disregard backoffice requests:
            //TODO. Use GlobalSettings.RequestIsInUmbracoApplication(HttpContext.Current)!!            
            if (UmbracoContext.Current == null || UmbracoContext.Current.HttpContext.Request.Url.AbsolutePath.StartsWith("/umbraco") || UmbracoContext.Current.HttpContext.Request.Url.AbsolutePath.StartsWith("/ScriptResource.axd")) //NOT WORKING!!!UmbracoContext.Current.IsFrontEndUmbracoRequest)
                return;

            HttpContext context = (sender as HttpApplication).Context;
         
            HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (authCookie != null)
            {
                //Extract the forms authentication cookie
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

                // If caching roles in userData field then extract
                FacebookPrincipalSerializableModel model = new JavaScriptSerializer().Deserialize<FacebookPrincipalSerializableModel>(authTicket.UserData);

                //Search roles: TODO: implement with mail address
                MembershipUser mUser = null;
                string[] roles = null;

                mUser = Authorize(model, out roles);                

                // Create the IPrinciple instance
                IPrincipal principal = new FacebookPrincipal(model.UniqueLink, roles)
                {
                    FirstName = model.FirstName,
                    UserName = model.UserName,
                    FacebookId = model.FacebookId,
                    AccessToken = model.AccessToken,
                    UniqueLink = model.UniqueLink,
                    EMail = model.EMail,
                    MembershipUser = mUser
                };

                // Set the context user 
                context.User = principal;

                if (principal.IsInRole("Triphulcas"))
                {
                    //if (String.IsNullOrEmpty(umbraco.BasePages.BasePage.umbracoUserContextID))
                    if (umbraco.BasePages.UmbracoEnsuredPage.CurrentUser == null)
                        // Hack. Set the Umbraco backoffice related user as logged - in
                        umbraco.BasePages.BasePage.doLogin(new User("triphulca"));
                }
            }
        }