NSURLConnection didReceiveAuthenticationChallenge weirdness
NSURLConnection didReceiveAuthenticationChallenge weirdness
- Subject: NSURLConnection didReceiveAuthenticationChallenge weirdness
- From: "Paul E. Robichaux" <email@hidden>
- Date: Tue, 17 Jun 2008 20:04:12 -0400
- Acceptlanguage: en-US
- Thread-topic: NSURLConnection didReceiveAuthenticationChallenge weirdness
I'm trying to properly respond to authentication challenges by overriding didReceiveAuthenticationChallenge. In the init method of my custom object, I take the user name and password passed in and create a NSURLCredential:
EWScreds = [NSURLCredential credentialWithUser: inUserName
password: inPassword
persistence:NSURLCredentialPersistenceForSession];
When I get an authentication challenge, I answer it with the stored credential:
-(void)connection:(MyURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0)
{
[[challenge sender] useCredential:EWScreds forAuthenticationChallenge:challenge];
}
else
NSLog(@"Authentication failed on attempt %d", [challenge previousFailureCount]);
}
This fails 100% of the time, even though the user name and password are correct. If I create a new credential using literal strings for the user name and password, like below, the auth challenge succeeds.
NSURLCredential *newCreds = nil;
newCreds = [NSURLCredential credentialWithUser: @"email@hidden"
password: @"AGreatPassword"
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCreds forAuthenticationChallenge: challenge];
I’ve verified that the password and user names match in both credentials (by using the user and password accessors on the credential objects). They appear to match. I’d appreciate any suggestions on what I might be doing wrong with this. Thanks in advance!
Cheers,
_Paul
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden