1

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;

4

2 回答 2

1

在某些情况下,这两种方法都适用于 UAG。如果您使用 HttpWebRequest,您可以通过在每次调用中设置基本授权和用户代理标头来向 UAG 进行身份验证。您不必将 cookie 传递给 UAG。SharePoint 将在下一次响应时返回数据。

您还可以修改上述 FBA 示例,使其适用于 UAG:您必须在 Authenticate 方法中添加 useragent 和基本身份验证标头。

spAuthReq.Headers["User-Agent"] = "Microsoft Office Mobile";
spAuthReq.Headers["Authorization"] = "Basic " . . .  

情侣小贴士:

  • 由于您将使用 HTTPS,因此您还需要将 clientconfig 安全模式更改为传输。
  • 在开始开发之前,针对您的 UAG/SharePoint 环境测试Office Hub 。
于 2012-09-22T18:17:41.620 回答
0

UAG 对 cookie 进行签名,这意味着每次用户登录时都会对它们进行混淆。UAG 也不进行 cookie 登录 - 它使用它们进行会话。

于 2012-08-24T13:30:35.750 回答