public static Cookie GetFedAuthCookie(string hostWeb, HttpCookie fedAuth) { //if (WebConfigurationManager.AppSettings["TestMode"] == "1") //{ // fedAuth = new HttpCookie("FedAuth"); // fedAuth.Value = WebConfigurationManager.AppSettings["FedAuthCookie"]; //} string domainCookie; if (string.IsNullOrEmpty(WebConfigure.GetLoginDomainForCookie())) { var httpReq = (HttpWebRequest)WebRequest.Create(hostWeb); domainCookie = httpReq.RequestUri.Host; } else { domainCookie = WebConfigure.GetLoginDomainForCookie(); } // Make Cookie from fedAuth var fedAuthCookie = new Cookie() { Domain = domainCookie, Expires = fedAuth.Expires, Name = fedAuth.Name, Path = fedAuth.Path, Secure = fedAuth.Secure, Value = String.IsNullOrEmpty(fedAuth.Value) ? "" : fedAuth.Value.Replace(' ', '+').Replace("%2B", "+"), }; return(fedAuthCookie); }
public static XDocument GetXDoc(string requestUrl, string acceptHeader, List <Cookie> cookies) { // prepare HttpWebRequest to execute REST API call var httpReq = (HttpWebRequest)WebRequest.Create(requestUrl); // add access token string as Authorization header httpReq.Accept = acceptHeader; var domainCookie = string.IsNullOrEmpty(WebConfigure.GetLoginDomainForCookie()) ? httpReq.RequestUri.Host : WebConfigure.GetLoginDomainForCookie(); httpReq.CookieContainer = new CookieContainer(); foreach (var cookie in cookies) { cookie.Domain = domainCookie; httpReq.CookieContainer.Add(cookie); } httpReq.UseDefaultCredentials = true; // execute REST API call and inspect response HttpWebResponse responseForUser = (HttpWebResponse)httpReq.GetResponse(); StreamReader readerUser = new StreamReader(responseForUser.GetResponseStream()); var xdoc = XDocument.Load(readerUser); readerUser.Close(); readerUser.Dispose(); return(xdoc); }
public static bool GetAuthorization(HttpRequestMessage request) { if (WebConfigure.GetMobileAuthorization() == request.Headers.GetValues("Authorization").FirstOrDefault()) { return(true); } else { return(false); } }
public static Dictionary <string, string> PushConf() { Dictionary <string, string> val = new Dictionary <string, string>(); val["primaindb"] = WebConfigure.GetMainConnectionString(); val["secdbempmst"] = WebConfigure.GetSecondaryEmpMasterConnectionString(); val["kymobauto"] = WebConfigure.GetMobileAuthorization(); val["kylgadm"] = WebConfigure.GetLoginManualXupj(); val["kydmn"] = WebConfigure.GetDomain(); val["kydmnch"] = WebConfigure.GetLoginDomainForCookie(); val["kyurlml"] = WebConfigure.GetUrlSendEmail(); val["kyhst"] = WebConfigure.GetLoginHost(); return(val); }
public static string GetUserXupj() { string xupj = ""; if (WebConfigure.GetLoginPortal() == "false") { xupj = WebConfigure.GetLoginManualXupj(); } else { try { var referer = HttpContext.Current.Request.UrlReferrer; HttpCookie userCookie = (HttpContext.Current.Request.Cookies.Get("sp") != null) ? HttpContext.Current.Request.Cookies.Get("sp") : null; HttpCookie fedAuth = HttpContext.Current.Request.Cookies.Get("FedAuth"); if (fedAuth != null) { fedAuth.Value = fedAuth.Value.Replace("%2B", "+"); } var isValid = SharepointHelper.IsValid(userCookie, fedAuth, referer); if (isValid) { string hostLogin = WebConfigure.GetLoginHost(); string protokol = HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://"; var host = protokol + hostLogin; var userId = SharepointHelper.GetUserId(host, @"application/atom+xml", fedAuth); xupj = userId; } } catch (Exception er) { LogErrorBService.WriteLog("Common", MethodBase.GetCurrentMethod().Name, er.ToString()); HttpContext.Current.Response.Cookies.Remove("sp"); HttpContext.Current.Response.Cookies.Remove("FedAuth"); throw; } } return(xupj); }