NSURLConnection using basic auth fails on Tiger, succeeds on Panther and Leopard

I have a program running on Panther, Tiger and Leopard systems and using the following authentication method NSURLConnection ("encodedUserPass" is an auth string with the word Basic followed by a base64 user: pass)

[theRequest addValue:encodedUserPass forHTTPHeaderField:@"Authorization"];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

      

... later ... in the didReceiveAuthenticationChallenge

if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:login_name password:password persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
}

      

This works fine on Panther and Leopard systems, but does not work completely on Tiger. The strange thing, however, is that even on Panther and Leopard it is usually called doReceiveAuthenticationChallenge (i.e. setting the headers manually doesn't seem to work).

In Tiger, doReceiveAuthenticationChallenge is always called, tries to respond as shown above, and then gets called again with an error.

Two questions: (i) Why is setting the headers manually not working? and (2) Why does the above method fail on Tiger (10.4)?

LATER UPDATE :

After some thought, I realized that there must be something wrong in my base64 encoding method, and it was: I did not add equal signs to convert the base64 string to several characters. I solved it with

while ([bareString length] % 4) [bareString appendString:@"="];

      

And now the program works on all three platforms. So the answer to question (i) is that setting the headers manually didn't work because I didn't fill with equal signs.

Question (ii) remains, however: why can't I use didReceiveAuthenticationChallenge successfully in Tiger?

+2


source to share


1 answer


I just stumbled across the same issue you described and found that NSURLCredentialPersistenceNone just doesn't work on Tiger whereas NSURLCredentialPersistenceForSession is stated .

Depending on your application, that may or may not be an acceptable solution.



Apple's documentation leaves a lot to be desired as it doesn't indicate what the scope of the "session" is until the application exits, maybe?

0


source







All Articles