Esempio n. 1
0
        internal static string GetCurrentEnvironment(bool useConsumerRps)
        {
            string result;

            if (useConsumerRps)
            {
                if (LiveIdAuthentication.consumerCurrentEnvironment == null)
                {
                    using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(true))
                    {
                        LiveIdAuthentication.consumerCurrentEnvironment = rpshttpAuthClient.GetCurrentEnvironment();
                    }
                }
                result = LiveIdAuthentication.consumerCurrentEnvironment;
            }
            else
            {
                if (LiveIdAuthentication.enterpriseCurrentEnvironment == null)
                {
                    using (RPSHttpAuthClient rpshttpAuthClient2 = LiveIdAuthentication.CreateRPSClient(false))
                    {
                        LiveIdAuthentication.enterpriseCurrentEnvironment = rpshttpAuthClient2.GetCurrentEnvironment();
                    }
                }
                result = LiveIdAuthentication.enterpriseCurrentEnvironment;
            }
            return(result);
        }
Esempio n. 2
0
        private static string GetRedirectUrl(LiveIdAuthentication.RedirectType rt, string siteName, string returnUrl, string authPolicy, bool useConsumerRps)
        {
            string constructUrlParam;

            if (rt == LiveIdAuthentication.RedirectType.Logout)
            {
                constructUrlParam = "Logout";
            }
            else if (rt == LiveIdAuthentication.RedirectType.SilentAuthenticate)
            {
                constructUrlParam = "SilentAuth";
            }
            else
            {
                constructUrlParam = "Auth";
            }
            string formattedReturnUrl;

            if (!LiveIdAuthentication.TryFormatUrl(returnUrl, out formattedReturnUrl))
            {
                formattedReturnUrl = returnUrl;
            }
            string result;

            using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(useConsumerRps))
            {
                int?   rpsErrorCode   = null;
                string rpsErrorString = null;
                string redirectUrl    = rpshttpAuthClient.GetRedirectUrl(constructUrlParam, siteName, formattedReturnUrl, authPolicy, out rpsErrorCode, out rpsErrorString);
                LiveIdAuthentication.ValidateRpsCallAndThrowOnFailure(rpsErrorCode, rpsErrorString);
                result = redirectUrl;
            }
            return(result);
        }
Esempio n. 3
0
        private static string GetSiteProperty(string siteName, string siteProperty, bool useConsumerRps)
        {
            string siteProperty2;

            using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(useConsumerRps))
            {
                siteProperty2 = rpshttpAuthClient.GetSiteProperty(siteName, siteProperty);
            }
            return(siteProperty2);
        }
Esempio n. 4
0
 public static void Logout(HttpContext httpContext, string siteName, bool useConsumerRps)
 {
     using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(useConsumerRps))
     {
         int?   rpsErrorCode   = null;
         string rpsErrorString = null;
         string logoutHeaders  = rpshttpAuthClient.GetLogoutHeaders(siteName, out rpsErrorCode, out rpsErrorString);
         LiveIdAuthentication.ValidateRpsCallAndThrowOnFailure(rpsErrorCode, rpsErrorString);
         LiveIdAuthentication.WriteHeadersToResponse(httpContext, logoutHeaders, useConsumerRps);
     }
 }
Esempio n. 5
0
        public static bool Authenticate(HttpContext httpContext, string siteName, string authPolicyOverrideValue, string[] memberNameIgnorePrefixes, bool useConsumerRps, out string puid, out string orgIdPuid, out string cid, out string membername, out uint issueTime, out uint loginAttributes, out string responseHeaders, out uint rpsTicketType, out RPSTicket deprecatedRpsTicketObject, out bool hasAcceptedAccrual, out uint rpsAuthState, out bool isOrgIdFederatedMsaIdentity)
        {
            if (!LiveIdAuthentication.IsInitialized)
            {
                throw new InvalidOperationException(Strings.ComponentNotInitialized);
            }
            if (siteName == null)
            {
                throw new ArgumentNullException("siteName");
            }
            hasAcceptedAccrual = false;
            puid                        = null;
            orgIdPuid                   = null;
            cid                         = null;
            membername                  = null;
            issueTime                   = 0U;
            loginAttributes             = 0U;
            responseHeaders             = null;
            rpsTicketType               = 0U;
            deprecatedRpsTicketObject   = null;
            rpsAuthState                = 0U;
            isOrgIdFederatedMsaIdentity = false;
            RPSPropBag rpspropBag = null;
            string     text       = httpContext.Request.QueryString["f"];

            if (!string.IsNullOrEmpty(text))
            {
                ExTraceGlobals.LiveIdAuthenticationModuleTracer.TraceError <string>(0L, "Querystring contains F-code: {0}.", text);
                return(false);
            }
            try
            {
                if (!useConsumerRps)
                {
                    rpspropBag = new RPSPropBag(LiveIdAuthentication.rpsOrgIdSession);
                }
                RPSProfile rpsprofile = null;
                using (RPSHttpAuthClient rpshttpAuthClient = LiveIdAuthentication.CreateRPSClient(useConsumerRps))
                {
                    int?   rpsErrorCode;
                    string rpsErrorString;
                    rpsprofile = rpshttpAuthClient.Authenticate(siteName, authPolicyOverrideValue, LiveIdAuthentication.sslOffloaded, httpContext.Request, rpspropBag, out rpsErrorCode, out rpsErrorString, out deprecatedRpsTicketObject);
                    LiveIdAuthentication.ValidateRpsCallAndThrowOnFailure(rpsErrorCode, rpsErrorString);
                }
                if (rpsprofile == null)
                {
                    return(false);
                }
                if (!useConsumerRps && deprecatedRpsTicketObject != null)
                {
                    try
                    {
                        using (RPSPropBag rpspropBag2 = new RPSPropBag(LiveIdAuthentication.rpsOrgIdSession))
                        {
                            rpspropBag2["SlidingWindow"] = 0;
                            if (!string.IsNullOrEmpty(authPolicyOverrideValue))
                            {
                                rpspropBag2["AuthPolicy"] = authPolicyOverrideValue;
                            }
                            if (!deprecatedRpsTicketObject.Validate(rpspropBag2))
                            {
                                return(false);
                            }
                        }
                    }
                    catch (COMException ex)
                    {
                        ExTraceGlobals.LiveIdAuthenticationModuleTracer.TraceError <COMException>(0L, "Failed to validate ticket: {0}.", ex);
                        LiveIdErrorHandler.ThrowRPSException(ex);
                    }
                }
                rpsAuthState  = rpsprofile.RPSAuthState;
                rpsTicketType = rpsprofile.TicketType;
                if (LiveIdAuthenticationModule.AppPasswordCheckEnabled && !httpContext.Request.Url.AbsolutePath.StartsWith("/owa/", StringComparison.OrdinalIgnoreCase) && rpsprofile.AppPassword)
                {
                    AppPasswordAccessException exception = new AppPasswordAccessException();
                    httpContext.Response.AppendToLog("&AppPasswordBlocked");
                    Utilities.HandleException(httpContext, exception, false);
                }
                hasAcceptedAccrual = LiveIdAuthentication.HasAcceptedAccruals(rpsprofile);
                orgIdPuid          = rpsprofile.HexPuid;
                cid        = (string.IsNullOrWhiteSpace(rpsprofile.ConsumerCID) ? rpsprofile.HexCID : rpsprofile.ConsumerCID);
                puid       = (string.IsNullOrWhiteSpace(rpsprofile.ConsumerPuid) ? orgIdPuid : rpsprofile.ConsumerPuid);
                membername = rpsprofile.MemberName;
                string text2;
                if (LiveIdAuthentication.TryRemoveMemberNamePrefixes(membername, memberNameIgnorePrefixes, out text2))
                {
                    membername = text2;
                    isOrgIdFederatedMsaIdentity = true;
                }
                issueTime       = rpsprofile.IssueInstant;
                loginAttributes = rpsprofile.LoginAttributes;
                string text3 = loginAttributes.ToString();
                httpContext.Response.AppendToLog("&loginAttributes=" + text3);
                if (!string.IsNullOrWhiteSpace(text3))
                {
                    httpContext.Response.AppendToLog(string.Format("loginAttributes={0}", text3));
                    httpContext.Request.Headers.Add("X-LoginAttributes", text3);
                }
                responseHeaders = rpsprofile.ResponseHeader;
            }
            finally
            {
                if (rpspropBag != null)
                {
                    rpspropBag.Dispose();
                }
            }
            return(true);
        }