I am trying to find a way to cancel credentials as soon as you install NSURLCredential with NSURLConnection using NSURLCredentialPersistenceForSession, but I could not find a working solution. Removing the NSURLCredential from the NSURLCredentialStorage only removes it from the repository and not from the NSURLConnection cache. I tried disabling the cache and it still saves it. I need this to be NSURLCredentialPersistenceForSession, since I do not want it to load big data, then return a message authentication request to you and then authenticate with NSURLConnection and then resend the big data, I just want to authenticate one times and send big data once. I have an authentication method before sending big data by checking some properties,but this does not allow me to log out or re-request authentication. I am writing a WebDav client so that you understand where I am standing, and the reason I need to disable credentials is if someone has several accounts on the WebDav server and you want to log in to another account. I tried to look in the cookies to make sure that there is something there, but it is not. I know this only for the session, which means that after completing the work and restarting the application, you can log in as another user. But it can confuse some people. I was thinking of writing my own authentication system, but I did not know how long it would take.- this is if someone has several accounts on the WebDav server and you want to log in to another account. I tried to look in the cookies to make sure that there is something there, but it is not. I know this only for the session, which means that after completing the work and restarting the application, you can log in as another user. But it can confuse some people. I was thinking of writing my own authentication system, but I did not know how long it would take.- this is if someone has several accounts on the WebDav server and you want to log in to another account. I tried to look in the cookies to make sure that there is something there, but it is not. I know this only for the session, which means that after completing the work and restarting the application, you can log in as another user. But it can confuse some people. I was thinking of writing my own authentication system, but I did not know how long it would take.I was thinking of writing my own authentication system, but I did not know how long it would take.I was thinking of writing my own authentication system, but I did not know how long it would take.
Sorry if the above message is too long, I just made sure to explain everything in detail so that someone could help me with the correct answer, and not go here to bring me to something that I tried.
Thanks for any help,
Gekko.
Update: sample code.
CFHTTPMessageRef message = [self httpMessageFromResponse:response];
authentication = CFHTTPAuthenticationCreateFromResponse(kCFAllocatorDefault, message);
CFHTTPMessageRef message = [self httpMessageFromRequest:request];
CFStreamError error;
CFHTTPMessageApplyCredentials(message, authentication, (CFStringRef)[credentials user], (CFStringRef)[credentials password], &error);
NSLog(@"%d", error.error);
CFStringRef value = CFHTTPMessageCopyHeaderFieldValue(message, CFSTR("Authorization"));
NSLog(@"%@", (NSString *)value);
if (value!=NULL)
CFRelease(value);
Update: The code I tried with credential deletion.
- (void)resetCredentials {
NSURLCredentialStorage *store = [NSURLCredentialStorage sharedCredentialStorage];
NSDictionary *allCredentials = [store allCredentials];
NSArray *keys = [allCredentials allKeys];
for (int i=0; i<[keys count]; i++) {
NSURLProtectionSpace *protectionSpace = [keys objectAtIndex:i];
NSDictionary *userToCredentialMap = [store credentialsForProtectionSpace:protectionSpace];
NSArray *mapKeys = [userToCredentialMap allKeys];
for (int u=0; u<[mapKeys count]; u++) {
NSString *user = [mapKeys objectAtIndex:u];
NSURLCredential *credential = [userToCredentialMap objectForKey:user];
NSLog(@"%@", credential);
[store removeCredential:credential forProtectionSpace:protectionSpace];
}
}
}