public async static Task <string> RetreiveICA(string WebURL, CitrixAuthCredential Creds, CitrixApplicationInfo AppInfo) { string SFURL = string.Format("{0}/{1}", WebURL, AppInfo.AppLaunchURL); bool IsSSL = false; if (SFURL.ToLower().IndexOf("https:") != -1) { IsSSL = true; } else { IsSSL = false; } var _ica = await GetICAFromStoreFront(SFURL, Creds, IsSSL); return(_ica); }
private async static Task <string> GetICAFromStoreFront(string SFURL, CitrixAuthCredential Creds, bool UseSSL) { CookieContainer _cookieContainer = new CookieContainer(); Uri _cookieUri = new Uri(SFURL); Cookie _aspnetSessionIdCookie = new Cookie("ASP.NET_SessionId", Creds.SessionID, Creds.CookiePath, Creds.CookieHost); Cookie _csrfTokenCookie = new Cookie("CsrfToken", Creds.CSRFToken, Creds.CookiePath, Creds.CookieHost); Cookie _authIDCookie = new Cookie("CtxsAuthId", Creds.AuthToken, Creds.CookiePath, Creds.CookieHost); _cookieContainer.Add(_cookieUri, _aspnetSessionIdCookie); _cookieContainer.Add(_cookieUri, _csrfTokenCookie); _cookieContainer.Add(_cookieUri, _authIDCookie); HttpClientHandler _clientHandler = new HttpClientHandler(); _clientHandler.CookieContainer = _cookieContainer; System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(_clientHandler); //_client.BaseAddress = new Uri(SFURL); if (UseSSL) { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "Yes"); } else { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "No"); } _client.DefaultRequestHeaders.Add("Csrf-Token", Creds.CSRFToken); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream")); StringContent _bodyContent = new StringContent(""); HttpResponseMessage _icaResponse = await _client.GetAsync(SFURL); string _icaFile = null; if (_icaResponse.StatusCode == HttpStatusCode.OK) { _icaFile = await _icaResponse.Content.ReadAsStringAsync(); } return(_icaFile); }
public async static Task <CitrixApplicationInfo> GetResource(string WebURL, CitrixAuthCredential Creds, bool UseSSL, string ApplicationName) { string SFURL = WebURL; bool IsSSL = false; if (SFURL.ToLower().IndexOf("https:") != -1) { IsSSL = true; } else { IsSSL = false; } var _resources = await GetResourcesFromStoreFront(SFURL, Creds, UseSSL); CitrixApplicationInfo _app = _resources.Find(a => a.AppTitle == ApplicationName); return(_app); }
public async static Task <string> RetreiveICA(string Server, string WebLocation, CitrixAuthCredential Creds, CitrixApplicationInfo AppInfo, bool UseSSL) { string SFURL = null; if (WebLocation.StartsWith("/")) { WebLocation = WebLocation.Substring(1, WebLocation.Length - 1); } if (UseSSL) { SFURL = string.Format("https://{0}/{1}/{2}", Server, WebLocation, AppInfo.AppLaunchURL); } else { SFURL = string.Format("http://{0}/{1}/{2}", Server, WebLocation, AppInfo.AppLaunchURL); } var _ica = await GetICAFromStoreFront(SFURL, Creds, UseSSL); return(_ica); }
private async static Task <CitrixAuthCredential> GetCredentialsFromStoreFront(string SFURL, string Username, string Password, string Domain, bool IsSSL) { CitrixAuthCredential _sfCredential = null; Dictionary <string, string> _returnedValues = new Dictionary <string, string>(); string _csrfToken = Guid.NewGuid().ToString(); string _aspnetSessionID = Guid.NewGuid().ToString(); string _username = Username; string _password = Password; string _domain = Domain; string _authenticationBody = string.Format(@"username={0}\{1}&password={2}", _domain, _username, _password); CookieContainer _cookieContainer = new CookieContainer(); HttpClientHandler _clientHandler = new HttpClientHandler(); _clientHandler.CookieContainer = _cookieContainer; System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(_clientHandler); //_client.BaseAddress = new Uri(SFURL); string _postAuthUrl = (SFURL.EndsWith("/")) ? "PostCredentialsAuth/Login" : "/PostCredentialsAuth/Login"; string _postURL = string.Format("{0}{1}", SFURL, _postAuthUrl); if (IsSSL) { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "Yes"); } else { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "No"); } _client.DefaultRequestHeaders.Add("Csrf-Token", _csrfToken); StringContent _bodyContent = new StringContent(_authenticationBody, Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage _authResp = await _client.PostAsync(_postURL, _bodyContent); if (_authResp.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(String.Format("Error: {0}", _authResp.ReasonPhrase)); } else { /* * <?xml version="1.0" encoding="UTF-8"?> * <AuthenticationStatus xmlns="http://citrix.com/deliveryservices/webAPI/2-6/authStatus"> * <Result>success</Result> * <AuthType>Certificate</AuthType> * </AuthenticationStatus> */ string _returnedContent = await _authResp.Content.ReadAsStringAsync(); System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Parse(_returnedContent); //XmlDocument doc = new XmlDocument(); //doc.LoadXml(_returnedContent); //XmlNamespaceManager _namespaceMgr = new XmlNamespaceManager(doc.NameTable); //_namespaceMgr.AddNamespace("mockns", @"http://citrix.com/delivery-services/webAPI/2-6/authStatus"); XNamespace ns = doc.Root.GetDefaultNamespace(); XElement _resultAuthNode = doc.Descendants(ns + "Result").SingleOrDefault(); //XmlNode _resultAuthNode = doc.SelectSingleNode("//mockns:Result", _namespaceMgr); if (_resultAuthNode != null) { //if (_resultAuthNode.InnerText.ToLower() == "success") if (_resultAuthNode.Value.ToLower() == "success") { string _cookiePath = "/"; string _cookieHost = _authResp.RequestMessage.RequestUri.Host; foreach (var header in _authResp.Headers.Where(i => i.Key == "Set-Cookie")) { foreach (string cookieValue in header.Value) { //"ASP.NET_SessionId=miphlcqdo53dwdipdxj3vp4i; path=/; HttpOnly" string[] cookieElements = cookieValue.Split(';'); string[] keyValueElements = cookieElements[0].Split('='); //path //string[] pathCookieElements = cookieElements[1].Split('='); //_cookiePath = pathCookieElements[1]; _returnedValues.Add(keyValueElements[0], keyValueElements[1]); } } _sfCredential = new CitrixAuthCredential { AuthToken = _returnedValues["CtxsAuthId"].ToString(), CSRFToken = _returnedValues["CsrfToken"].ToString(), SessionID = _returnedValues["ASP.NET_SessionId"].ToString(), CookiePath = _cookiePath, CookieHost = _cookieHost, StorefrontUrl = SFURL }; } } else { _sfCredential = null; } } return(_sfCredential); }
public async static Task <CitrixApplicationInfo> GetResource(string Server, string WebLocation, CitrixAuthCredential Creds, bool UseSSL, string ApplicationName) { string SFURL = null; if (WebLocation.StartsWith("/")) { WebLocation = WebLocation.Substring(1, WebLocation.Length - 1); } if (UseSSL) { SFURL = string.Format("https://{0}/{1}", Server, WebLocation); } else { SFURL = string.Format("http://{0}/{1}", Server, WebLocation); } var _resources = await GetResourcesFromStoreFront(SFURL, Creds, UseSSL); CitrixApplicationInfo _app = _resources.Find(a => a.AppTitle == ApplicationName); return(_app); }
public async static Task <List <CitrixApplicationInfo> > GetResources(string WebURL, CitrixAuthCredential Creds, bool UseSSL) { string SFURL = WebURL; bool IsSSL = false; if (SFURL.ToLower().IndexOf("https:") != -1) { IsSSL = true; } else { IsSSL = false; } var _resources = await GetResourcesFromStoreFront(SFURL, Creds, UseSSL); return(_resources); }
private async static Task <List <CitrixApplicationInfo> > GetResourcesFromStoreFront(string SFURL, CitrixAuthCredential Creds, bool UseSSL) { List <CitrixApplicationInfo> _applicationList = new List <CitrixApplicationInfo>(); CookieContainer _cookieContainer = new CookieContainer(); Cookie _aspnetSessionIdCookie = new Cookie("ASP.NET_SessionId", Creds.SessionID, Creds.CookiePath, Creds.CookieHost); Cookie _csrfTokenCookie = new Cookie("CsrfToken", Creds.CSRFToken, Creds.CookiePath, Creds.CookieHost); Cookie _authIDCookie = new Cookie("CtxsAuthId", Creds.AuthToken, Creds.CookiePath, Creds.CookieHost); _cookieContainer.Add(_aspnetSessionIdCookie); _cookieContainer.Add(_csrfTokenCookie); _cookieContainer.Add(_authIDCookie); HttpClientHandler _clientHandler = new HttpClientHandler(); _clientHandler.CookieContainer = _cookieContainer; System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(_clientHandler); _client.BaseAddress = new Uri(SFURL); string _postResourceUrl = (SFURL.EndsWith("/")) ? "Resources/List" : "/Resources/List"; string _resourcesURL = SFURL + _postResourceUrl; if (UseSSL) { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "Yes"); } else { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "No"); } _client.DefaultRequestHeaders.Add("Csrf-Token", Creds.CSRFToken); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); StringContent _bodyContent = new StringContent(""); HttpResponseMessage _listResourcesResp = await _client.PostAsync(_resourcesURL, _bodyContent); if (_listResourcesResp.StatusCode == HttpStatusCode.OK) { string _resourcesJSON = await _listResourcesResp.Content.ReadAsStringAsync(); JObject _resourcesBase = JObject.Parse(_resourcesJSON); _applicationList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CitrixApplicationInfo> >(_resourcesBase["resources"].ToString()); foreach (var _resource in _applicationList) { _resource.Auth = Creds; //_resource.StorefrontURL; } } return(_applicationList); }
public async static Task <List <CitrixApplicationInfo> > GetResourcesFromStoreFront(string SFURL, CitrixAuthCredential Creds, bool UseSSL) { List <CitrixApplicationInfo> _applicationList = new List <CitrixApplicationInfo>(); CookieContainer _cookieContainer = new CookieContainer(); Cookie _aspnetSessionIdCookie = new Cookie("ASP.NET_SessionId", Creds.SessionID, Creds.CookiePath, Creds.CookieHost); Cookie _csrfTokenCookie = new Cookie("CsrfToken", Creds.CSRFToken, Creds.CookiePath, Creds.CookieHost); Cookie _authIDCookie = new Cookie("CtxsAuthId", Creds.AuthToken, Creds.CookiePath, Creds.CookieHost); Uri _cookieUri = new Uri(SFURL); _cookieContainer.Add(_cookieUri, _aspnetSessionIdCookie); _cookieContainer.Add(_cookieUri, _csrfTokenCookie); _cookieContainer.Add(_cookieUri, _authIDCookie); HttpClientHandler _clientHandler = new HttpClientHandler(); _clientHandler.CookieContainer = _cookieContainer; System.Net.Http.HttpClient _client = new System.Net.Http.HttpClient(_clientHandler); //_client.BaseAddress = new Uri(SFURL); string _postResource = (SFURL.EndsWith("/")) ? "Resources/List" : "/Resources/List"; string _postResourceUrl = string.Format("{0}{1}", SFURL, _postResource); if (UseSSL) { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "Yes"); } else { _client.DefaultRequestHeaders.Add("X-Citrix-IsUsingHTTPS", "No"); } _client.DefaultRequestHeaders.Add("Csrf-Token", Creds.CSRFToken); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); StringContent _bodyContent = new StringContent(""); HttpResponseMessage _listResourcesResp = await _client.PostAsync(_postResourceUrl, _bodyContent); if (_listResourcesResp.StatusCode == HttpStatusCode.OK) { string _resourcesJSON = await _listResourcesResp.Content.ReadAsStringAsync(); //check for the authorized object. // "{\"unauthorized\": true}" JObject _resourcesBase = JObject.Parse(_resourcesJSON); JArray _resources = (JArray)_resourcesBase["resources"]; foreach (var _resource in _resources) { CitrixApplicationInfo _appInfo = new CitrixApplicationInfo(); _appInfo.AppTitle = _resource["name"].ToString(); try { _appInfo.AppDesc = _resource["description"].ToString(); } catch (Exception e) { _appInfo.AppDesc = ""; } _appInfo.AppIconUrl = _resource["iconurl"].ToString(); _appInfo.AppLaunchURL = _resource["launchurl"].ToString(); _appInfo.ID = _resource["id"].ToString(); _applicationList.Add(_appInfo); } } return(_applicationList); }