【问题标题】:iOS "didReceiveAuthenticationChallenge" against IIS7 and Windows 2008针对 IIS7 和 Windows 2008 的 iOS“didReceiveAuthenticationChallenge”
【发布时间】:2012-08-16 11:32:35
【问题描述】:

我在 iOS 编程中遇到了一些身份验证问题。我有一个代码可以在 Windows 2003 上完美地对抗 IIS6,但不能在带有 IIS7 的 Windows Server 2008 上工作。两台服务器上的安全选项相同(无匿名访问和“集成 Windows 身份验证”)。

这是“didReceiveAuthenticationChallenge”委托的代码:

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:
(NSURLAuthenticationChallenge *)challenge 
{
//USE STORED CREDENTIALS
Credentials* cred = [[Credentials alloc] init];
NSString* userName = cred.userName;
NSString* pass = cred.pass;

NSString* authMethod = [[challenge protectionSpace] authenticationMethod];

//Kerberos (Negotiate) needs "user@realm" as username
//NTLM Needs domain\\username
if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) {
    userName = [NSString stringWithFormat:@"%@%@", @"es\\" , userName];
}
if ([authMethod isEqualToString:NSURLAuthenticationMethodNegotiate]) {
    userName = [NSString stringWithFormat:@"%@%@", userName, @"@subdomain.domain.com"];
}

NSLog(@"Auth method in use: %@" , authMethod);
NSLog(@"User: %@" , userName);
NSLog(@"Pass: %@" , pass);

if ([challenge previousFailureCount] <= 1) {
    NSLog(@"received authentication challenge");
    NSURLCredential *credential;
    credential = [NSURLCredential 
                     credentialWithUser:userName 
                     password:pass
                     persistence:NSURLCredentialPersistenceForSession];        

    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];

}
else {
    NSLog(@"Authentication error");
    NSLog(@"Failed login with status code: %d", [(NSHTTPURLResponse*)[challenge failureResponse]statusCode]);
    [[challenge sender] cancelAuthenticationChallenge:challenge];   
}   

}

【问题讨论】:

  • didReceiveAuthenticationChallenge 方法是否被调用?
  • 是的,它被调用了,我可以在那里放置一些断点(并且代码可以从 W2003 服务器工作)
  • “不幸的是”我没有看到你的 iOS 方法有什么不寻常的地方。是否有机会调查质询响应是否返回服务器,如果返回,那里会发生什么?

标签: ios iis iis-7


【解决方案1】:

终于找到了bug...问题与Windows 2008 IIS7 Servers上的Authentication方法有关。

当您使用“集成 Windows 身份验证”时,服务器可以使用 NTLM 或 Kerberos。我的 2008 服务器始终使用 kerberos,即使这些机器上没有配置 Kerberos。

解决方案是编辑 IIS 元数据库以强制 NTML 身份验证。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多