In a Windows Phone application, I'm trying to read SharePoint data that is protected by UAG, and want to support passing a session cookie to UAG.
The white paper, Building Windows Phone 7 applications with SharePoint 2010 Products and Unified Access Gateway (UAG), http://technet.microsoft.com/en-us/library/hh180841.aspx, demonstrates passing user credentials each time to UAG.
But, how do I store and reuse the session cookie that UAG passes back to the client?
//Example from white paper string url = String.Format(“{0}/my/_layouts/activityfeed.aspx?consolidated=true", AppSettings.Url); System.Uri authServiceUri = new Uri(url); HttpWebRequest client = WebRequest.CreateHttp(authServiceUri) as HttpWebRequest; client.Headers["User-Agent"] = "Microsoft Office Mobile"; client.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(AppSettings.Username + ":" + AppSettings.Password))+ System.Environment.NewLine; // Call and handle the response...
This Blog Post, Developing Windows Phone 7 Applications for SharePoint 2010, http://blogs.msdn.com/b/pstubbs/archive/2010/10/04/developing-windows-phone-7-applications-for-sharepoint-2010.aspx, shows how to authenticate with FBA and pass a cookie with request. But I don't know how much of this applies to UAG.
private void Authenticate() { System.Uri authServiceUri =new Uri("http://phone.contoso.com/_vti_bin/authentication.asmx"); HttpWebRequest spAuthReq = HttpWebRequest.Create(authServiceUri) as HttpWebRequest; spAuthReq.CookieContainer = cookieJar; spAuthReq.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/Login"; spAuthReq.ContentType = "text/xml; charset=utf-8"; spAuthReq.Method = "POST"; //add the soap message to the request spAuthReq.BeginGetRequestStream(new AsyncCallback(spAuthReqCallBack), spAuthReq); } // After authenticated and cookie is set ListsService.ListsSoapClient lists = new ListsService.ListsSoapClient(); lists.CookieContainer = cookieJar;