Exemple #1
0
        public static void WriteHeadersToResponse(HttpContext httpContext, string headers, bool useConsumerRps)
        {
            HttpResponse response = httpContext.Response;

            if (!"no-cache".Equals(response.CacheControl, StringComparison.OrdinalIgnoreCase) && !"no-store".Equals(response.CacheControl, StringComparison.OrdinalIgnoreCase) && !"private".Equals(response.CacheControl, StringComparison.OrdinalIgnoreCase))
            {
                response.Cache.SetCacheability(HttpCacheability.NoCache, "set-cookie");
            }
            try
            {
                using (RPSHttpAuth rpshttpAuth = new RPSHttpAuth(LiveIdAuthentication.rpsOrgIdSession))
                {
                    if (AuthCommon.IsFrontEnd || CafeHelper.IsFromNativeProxy(httpContext.Request))
                    {
                        rpshttpAuth.WriteHeaders(response, headers);
                    }
                    else
                    {
                        response.SetCookie(new HttpCookie("CopyLiveIdAuthCookieFromBE", HttpUtility.UrlEncode(headers)));
                    }
                }
            }
            catch (COMException e)
            {
                LiveIdErrorHandler.ThrowRPSException(e);
            }
        }
Exemple #2
0
        private void clearLiveIDCookies()
        {
            HttpResponse response    = (HttpResponse)HttpContext.Items["originalResponse"];
            RPS          myRps       = (RPS)HttpContext.Application["globalRPS"];
            string       siteDnsName = HttpContext.Request.ServerVariables["SERVER_NAME"];

            RPSHttpAuth rpsHttpAuth = new RPSHttpAuth(myRps);

            string rLogoutHeaders = rpsHttpAuth.GetLogoutHeaders(siteDnsName);

            rpsHttpAuth.WriteHeaders(response, rLogoutHeaders);
        }
        public IUser GetUser(RequestContext context)
        {
            HttpRequest request = (HttpRequest)context.HttpContext.Items["originalRequest"];

            if (context.HttpContext.Items.Contains("CalledLiveIDAlready"))
            {
                if (context.HttpContext.Items.Contains(typeof(IUser).FullName))
                {
                    return(context.HttpContext.Items[typeof(IUser).FullName] as IUser);
                }
            }


            context.HttpContext.Items.Add("CalledLiveIDAlready", "Did it");

            HttpResponse response    = (HttpResponse)context.HttpContext.Items["originalResponse"];
            IUserService userService = container.Resolve <IUserService>();

            // Get the RPS object preinitialized in the Global.asax
            RPS myRps = GetRPS(context);

            if (myRps == null)
            {
                return(null);
            }
            string siteName = GetSiteName();

            // Create other base RPS objects.
            RPSHttpAuth  httpAuth    = new RPSHttpAuth(myRps);
            RPSPropBag   authPropBag = new RPSPropBag(myRps);
            RPSDomainMap domainMap   = new RPSDomainMap(myRps);

            RPSServerConfig mainConfig = new RPSServerConfig(myRps);
            RPSPropBag      siteConfig = (RPSPropBag)mainConfig["Sites"];

            RPSPropBag mySiteConfig = (RPSPropBag)siteConfig[siteName];

            int siteID = Convert.ToInt32(mySiteConfig["SiteID"]);

            // Set returnUrl and siteID in authPropBag.

            // Determine if SSL should be used.
            string returnUrl;

            if (context.HttpContext.Request.IsSecureConnection)
            {
                returnUrl = "https://"
                            + context.HttpContext.Request.ServerVariables["SERVER_NAME"]
                            + context.HttpContext.Request.Path;
            }
            else
            {
                returnUrl = "http://"
                            + context.HttpContext.Request.ServerVariables["SERVER_NAME"]
                            + context.HttpContext.Request.Path;
            }

            authPropBag["ReturnURL"] = returnUrl;
            authPropBag["SiteID"]    = siteID;

            // Create ticket object and populate the authPropBag with
            // values from the Request object.
            RPSTicket ticket = httpAuth.Authenticate(siteName, request, authPropBag);

            // Get the user's 'authState' to determine if user is currently signed in.
            uint authState = (uint)authPropBag["RPSAuthState"];

            if (ticket == null)
            {
                //No RPSTicket found.  Check for AuthState=2 (Maybe) state.
                if (authState == 2)
                {
                    // RPS Maybe state detected. Indicates a ticket is present,
                    // but cannot be read. Redirect to SilentAuth URL to obtain
                    // a fresh RPS Ticket. Write RPS response headers to write
                    // the Maybe state cookie to prevent looping.
                    string rpsHeaders = (string)authPropBag["RPSRespHeaders"];
                    if (rpsHeaders != "")
                    {
                        httpAuth.WriteHeaders(response, rpsHeaders);
                    }

                    string silentAuthUrl =
                        domainMap.ConstructURL(
                            "SilentAuth",
                            siteName,
                            null,
                            authPropBag);
                    context.HttpContext.Response.Redirect(silentAuthUrl);
                }
                else
                {
                    // User is not signed in.  Show page with Sign-in option.

                    //Message.Text = "A ticket was not detected. "
                    //    + "Click the sign in button below to sign in.";
                    //ShowTicketProperties.Text = "";
                    //bool showSignIn = true;
                    //bool isSecure = Request.IsSecureConnection;

                    //LogoButton.Text =
                    //    httpAuth.LogoTag(
                    //        showSignIn,
                    //        isSecure,
                    //        null,
                    //        null,
                    //        siteName,
                    //        authPropBag);
                }
            }
            else
            {
                // RPS ticket found. Ensure ticket is valid (signature is valid
                // and policy criteria such as time window and use of SSL are met).

                bool isValid = ticket.Validate(authPropBag);

                if (!isValid)
                {
                    // RPS ticket exists, but is not valid. Refresh ticket by
                    // redirecting user to Auth URL. If appropriate Login server
                    // cookies exist, ticket refresh will be transparent to the user.
                    context.HttpContext.Response.Redirect(
                        domainMap.ConstructURL(
                            "Auth",
                            siteName,
                            null,
                            authPropBag));
                }
                else
                {
                    //Get RPS response headers from authPropBag and write to response stream
                    string rpsHeaders = (string)authPropBag["RPSRespHeaders"];
                    if (rpsHeaders != "")
                    {
                        httpAuth.WriteHeaders(response, rpsHeaders);
                    }

                    UserAuthenticated user = userService.GetUserByModuleData("LiveID", (string)ticket.Property["HexPUID"]);

                    if (user == null)
                    {
                        UrlHelper urlHelper = new UrlHelper(context);

                        if (!urlHelper.IsRegisterRoute() && !urlHelper.IsSignOutRoute() && !urlHelper.IsErrorRoute())
                        {
                            context.HttpContext.Response.Redirect(urlHelper.Register(), true);
                        }

                        IDictionary <string, object> values = new Dictionary <string, object>();

                        values.Add("PUID", (string)ticket.Property["HexPUID"]);
                        values.Add("FirstName", (string)ticket.ProfileProperty["firstname"]);
                        values.Add("LastName", (string)ticket.ProfileProperty["lastname"]);

                        return(new UserUnregistered("Unregistered User", "LiveID", values));
                    }
                    else
                    {
                        user.AuthenticationValues["PUID"]      = (string)ticket.Property["HexPUID"];
                        user.AuthenticationValues["FirstName"] = (string)ticket.ProfileProperty["firstname"];
                        user.AuthenticationValues["LastName"]  = (string)ticket.ProfileProperty["lastname"];
                    }

                    return(user);
                }
            }


            return(new UserAnonymous());
        }