如何使用会话cookie以编程方式使用Windows Phone应用程序对UAG for SharePoint进行身份验证

时间:2012-08-09 01:44:41

标签: windows-phone-7 sharepoint authentication

在Windows Phone应用程序中,我正在尝试读取受UAG保护的SharePoint数据,并希望支持将会话cookie传递给UAG。

白皮书“使用SharePoint 2010产品和统一接入网关(UAG)构建Windows Phone 7应用程序http://technet.microsoft.com/en-us/library/hh180841.aspx,演示了每次将用户凭据传递给UAG。
但是,如何存储和重用UAG传回客户端的会话cookie?


    //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...

此博客文章,为SharePoint 2010开发Windows Phone 7应用程序http://blogs.msdn.com/b/pstubbs/archive/2010/10/04/developing-windows-phone-7-applications-for-sharepoint-2010.aspx,演示了如何使用FBA进行身份验证并通过请求传递cookie。但我不知道有多少适用于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;

3 个答案:

答案 0 :(得分:1)

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

您还可以修改上面的FBA示例,以便它可以与UAG一起使用: 您必须在Authenticate方法中添加useragent和基本身份验证标头。

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

夫妻小贴士:

  • 由于您将使用HTTPS,因此您还需要将clientconfig安全模式更改为transport。
  • 在开始开发之前,针对您的UAG / SharePoint环境测试Office Hub

答案 1 :(得分:0)

UAG签署cookie,这意味着每次用户登录时都会对其进行模糊处理。此外,UAG不会进行cookie登录 - 它会将其用于会话。

答案 2 :(得分:0)