在iPhone上声明对SharePoint的身份验证

时间:2012-09-09 01:59:57

标签: iphone ios sharepoint sharepoint-2010 claims-based-identity

我为iPhone制作了一个简单的SharePoint客户端应用程序,它需要访问一些SharePoint Web服务(主要是/_vti_bin/Lists.asmx)。我在查找如何在较新的SharePoint环境(如Office365)上执行此操作时遇到了麻烦。

对于具有基于表单的身份验证的旧BPOS环境,我只需实现didReceiveAuthenticationChallenge方法即可对这些服务进行身份验证;

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSURLCredential *newCredential = [NSURLCredential credentialWithUser:username
                                               password:password
                                            persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:newCredential
       forAuthenticationChallenge:challenge];
}

这显然不再适用于具有声明身份验证的SharePoint网站,因此我做了一些研究,发现我需要将FedAuth个Cookie附加到请求中。

http://msdn.microsoft.com/en-us/library/hh147177.aspx

根据这篇文章,使用.NET Apps,似乎可以使用WININET.dll检索那些HTTPOnly FedAuth cookie,但我想这在iPhone上不可用?

然后,我看到SharePlus应用程序呈现UIWebView并让用户首先在浏览器屏幕上登录他们的Office365帐户(这与“启用远程身份验证的用户登录”中所述的概念相同上面文章的部分)。

所以,我试图通过FedAuth登录Office365帐户,以某种方式获取对这些UIWebView Cookie的访问权限,但[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]不允许我访问HTTPOnly Cookie。< / p>

有没有办法在iPhone应用程序上实现声明身份验证,而无需指定中间.NET服务来处理身份验证,或者要求用户关闭这些Cookie上的HTTPOnly属性?

抱歉,我对SharePoint非常陌生,所以我甚至可能没有找到正确的方向,但我很感激任何有关获取iPhone应用程序的声明身份验证的建议。提前谢谢!

1 个答案:

答案 0 :(得分:2)

我自己已经弄明白了。不得不嘲笑我自己的愚蠢和不耐烦。

首先,[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] DO允许您访问HTTPOnly cookie。但是,当用户在UIWebView上登录Office 365时,(void)webViewDidFinishLoad:(UIWebView *)webView委托方法会被多次调用,因此您只需要等到FedAuth出现在Cookie jar中。

这是我的(void)webViewDidFinishLoad:(UIWebView *)webView实施;

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookiesArray = [storage cookies];
    for (NSHTTPCookie *cookie in cookiesArray) {
        if ([[cookie name] isEqualToString:@"FedAuth"]) {
            /*** DO WHATEVER YOU WANT WITH THE COOKIE ***/
            break;
        }
    }
}

获得Cookie后,只需在调用SharePoint Web服务时使用NSURLRequest方法将其附加到(void)setAllHTTPHeaderFields:(NSDictionary *)headerFields

希望这有助于某人。

相关问题