views:

85

answers:

1

Hi,

Given a rails application which communicates with my ipad app. I'm using async connection with http authentication. And i would like to test the credentials if they are ok. The problem is that if i enter the good credentials and after that i'm changing to a wrong one, the connection still accepts. Only refuses when I reopen the application. Might be some caching issue, i tried to clear the cache also on the ipad.

Connection initialization.

 NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0];
[NSURLConnection connectionWithRequest:request delegate:self];

also implemented the willcacheresponse method

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
+1  A: 

Do you happen to cache the credential cache? If not, you can neglect all the following:)

I don't know which authentication mode you choose, here I have an sample using Windows authentication mode in my iphone app. When server side challenges client side, my app will send back a NSURLCredential object:

NSURLCredential* credential = [NSURLCredential credentialWithUser:login password:password persistence:NSURLCredentialPersistenceForSession];

Here you can see the parameter NSURLCredentialPersistenceForSession, following are the description:

typedef enum {
 NSURLCredentialPersistenceNone,       // Credential won't be stored.
 NSURLCredentialPersistenceForSession, // Credential will be stored only for this session.
 NSURLCredentialPersistencePermanent   // Credential will be stored in the user’s keychain and shared with other applications.
} NSURLCredentialPersistence;  

As you can see, if you use NSURLCredentialPersistenceForSession, the credential will be cached, and the callback connection: didReceiveAuthenticationChallenge: will never be called when server challenges client unless you clear it in NSURLCredentialStorage. So this makes your change of credential useless. You can use NSURLCredentialPersistenceNone to disable the cache or clear the cache when necessory.

olinYY
Tried this. Disabled the cache. Anyway great point, thanks.
dombesz