Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't reauthenticate with different NSURLCredentials (old deleted ones are used)
    text
    copied!<p>i've been searching stackoverflow, google, apple and other places. The tips provided look promising, i implemented them but alltogether don't seem to work or get enforced. </p> <p>Problem: I have an <code>NSURLConnection</code> with specific credentials. I then have a logout where I clear the credentials, the protectionspace, i remove all cached responses and delete all cookies in the <code>sharedHTTPCookieStorage</code> but when calling my authenticated request again a few seconds later even with wrong credentials I still am using the old (deleted) credentials</p> <p>Here are some code extracts, where credentials are removed</p> <pre><code> NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials]; if ([credentialsDict count] &gt; 0) { // the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName =&gt; NSURLCredential NSEnumerator *protectionSpaceEnumerator = [credentialsDict keyEnumerator]; id urlProtectionSpace; // iterate over all NSURLProtectionSpaces while (urlProtectionSpace = [protectionSpaceEnumerator nextObject]) { NSEnumerator *userNameEnumerator = [[credentialsDict objectForKey:urlProtectionSpace] keyEnumerator]; id userName; // iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials while (userName = [userNameEnumerator nextObject]) { NSURLCredential *cred = [[credentialsDict objectForKey:urlProtectionSpace] objectForKey:userName]; WriteLog(@"Method: switchView removing credential %@",[cred user]); [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:cred forProtectionSpace:urlProtectionSpace]; } } } </code></pre> <p>I then remove all cached responses</p> <pre><code> NSURLCache *sharedCache = [NSURLCache sharedURLCache]; [sharedCache removeAllCachedResponses]; </code></pre> <p>I then delete all cookies</p> <pre><code> NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray *cookies = [cookieStorage cookies]; for (NSHTTPCookie *cookie in cookies) { [cookieStorage deleteCookie:cookie]; NSLog(@"deleted cookie"); } </code></pre> <p>I also tried using no cookies and other policies</p> <pre><code> NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0]; [request setHTTPShouldHandleCookies:NO]; if(self.currentCookies != nil){ [request setAllHTTPHeaderFields: [NSHTTPCookie requestHeaderFieldsWithCookies:nil]]; } theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; </code></pre> <p>I also tried this hint here on specifically storing the cookies and passing them again. <a href="http://www.hanspinckaers.com/multiple-nsurlrequests-with-different-cookies" rel="nofollow noreferrer">http://www.hanspinckaers.com/multiple-nsurlrequests-with-different-cookies</a>. There's another blog on the web suggesting to add a "#" to each URL in order to enforce reauthentication, which works but just does not solve the issue because I need to count on session's credentials and the ability to use totally different credentials.</p> <p>Is this a bug or known issue and how do I really solve this... Put bluntly: What am I exactly doing wrong here?</p> <p>This is really bugging me and keeping me from continuing my work.</p> <p>I would greatly appreciate any input!</p> <p>Thanks alot!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload