针对 IIS7 和 Windows 2008 的 iOS "didReceiveAuthenticationChallenge"

标签 ios iis iis-7

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

这是“didReceiveAuthenticationChallenge”委托(delegate)的代码:

-(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];   
}   

最佳答案

最后,我找到了错误...问题与 Windows 2008 IIS7 服务器上的身份验证方法有关。

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

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

关于针对 IIS7 和 Windows 2008 的 iOS "didReceiveAuthenticationChallenge",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11986206/

相关文章:

ios - UITableView 半粘性 tableView Header 类似 App Store 详细 View

c# - 以编程方式查找 ASP.NET 工作进程和应用程序域上次启动的时间?

iis - 将整个经典 ASP 网站重定向到新域的最佳方法是什么?

asp.net - 由于 HttpModule 导致客户端缓存关闭?

asp.net - 如何更改 IIS 7.0 的 maxAllowedContentLength?

c# - 信号器/集线器和 jquery 脚本上的 404 错误

iis-7 - IIS7 Url Rewrite - 为什么重定向起作用而重写不起作用?

ios - 传递文本字段文本值 Swift 4

ios - 获取Major/Minor值 'without'监控?

ios - Apple 发布的 64 位支持公告对 Worklight 6.1 开发人员有何影响?