HTTP Authentication Headers for Windows IIS Authentication

I have a website hosted in IIS with Windows Authentication. I am trying to access it in one of my iPhone applications. I am currently using this code, but it doesn't work.

NSString * authString = [[[NSString stringWithFormat: @ "% @:% @", @ "myusername", @ "mypassword"] dataUsingEncoding: NSUTF8StringEncoding] base64Encoding];

authString = [NSString stringWithFormat: @"Basic %@", authString];

**[requestObj setValue:authString forHTTPHeaderField:@"Authorization"];**

      

my web app is hosted with windows authentication. but here I am using basic. can anyone post what is the correct http header for it.

Thanks..

0


a source to share


4 answers


I think the main difference is that you need to provide the domain that you are authenticating with, as well as the username and password. Something like this should work. I used a synchronous request for brevity, ideally you should use an ASINetworkQueue or NSOperationQueue to make the request.

NSString *username = @"test";
NSString *password = @"test";
NSString *domain = @"test";
NSURL *url = [NSURL URLWithString:@"http://myurl"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUseSessionPersistence:YES];
[request setUsername:username];
[request setPassword:password];
[request setDomain:domain];
[request start];
if ([request error]) {
    if ([[request error] code] == ASIAuthenticationErrorType) {
        //Authentication failed
    }
} else {
    NSLog([request responseString]);
}

      



I don't have access to a windows server to test this, but I've tested NTLM in the past, so it should work ... :)

+4


a source


Windows Authentication (NTLM) is not as easy as Basic Authentication. NTLM requires more than one web request to negotiate security, so there is no static HTTP header you can send for login.



+1


a source


You can use the third party ASIHTTPRequest library to perform NTLM authentication over HTTP.

0


a source


I'm not 100% sure if it supports NTLM authentication, but have you investigated the method connection:didReceiveAuthenticationChallenge

in NSUrlConnection?

0


a source