internal static string PerformAuthentication(Resources context) { AcsResponse param = new AcsResponse(); BrowserForm browserForm = new BrowserForm(aosUrl, param); WindowsForms.Application.Run(browserForm); // Debug.Assert(!browserForm.NavigationCanceled, "Unable to perform authentication to AOS"); HttpWebRequest httpRequest; HttpWebResponse httpResponse; CookieContainer cookieContainer = new CookieContainer(); httpRequest = (HttpWebRequest)WebRequest.Create(aosUrl); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; // // Authentication was done by using the hostname URI and not // full request URI. Hence, we should not let autoredirect // happen. // httpRequest.AllowAutoRedirect = false; httpRequest.CookieContainer = cookieContainer; StreamWriter writer = new StreamWriter(httpRequest.GetRequestStream(), Encoding.ASCII); writer.Write(param.GetAcsResponseString()); writer.Flush(); writer.Close(); httpResponse = (HttpWebResponse)httpRequest.GetResponse(); httpResponse.Close(); StringBuilder retval = new StringBuilder(); CookieCollection cookiesCollection = cookieContainer.GetCookies(new Uri(aosUrl)); if (cookiesCollection.Count > 0) { foreach (Cookie c in cookiesCollection) { retval.AppendFormat("{0}={1}; ", c.Name, c.Value); } //Remove the trailing "; " retval.Remove(retval.Length - 2, 2); } cookies = retval.ToString(); context.SendingRequest += new EventHandler <SendingRequestEventArgs>(OnSendingRequest); return(cookies); }
private void SetAcsResponseParam(AcsResponse param) { m_acsResponseParam = param; }
public BrowserForm(String url, AcsResponse param) { SetUrl(url); SetAcsResponseParam(param); InitializeComponent(); }