Reputation: 7068
I am using RestKit pretty basically with RKClient
and doing a get
request. My system uses username/password/account to authenticate the user. It is just httpbasic for username/password and the account is just a subdomain.
The issue I have is that if I do the following:
I put puts before and after setting the username and password and I can see it is being changed to incorrect data. And I've set caching to be RKRequestCachePolicyNone
(both on the shared client and on the RKRequest instance).
The returned request says it wasn't pulled from cache. And when I try to duplicate the issue in terminal using curl I get the correct response (that I can't get the data with the wrong username password).
So why/how would RestKit get the proper response back? It is hitting the server and getting a 200 response back.
- (void)startDownload {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"username and password before (%@,%@)",[RKClient sharedClient].username,[RKClient sharedClient].password);
[RKClient sharedClient].username = self.login;
[RKClient sharedClient].password = self.password;
NSLog(@"username and password after (%@,%@)",[RKClient sharedClient].username,[RKClient sharedClient].password);
NSString *base = [NSString stringWithFormat:@"http://%@.%@api",self.accountName,[defaults stringForKey:@"myURL"]];
[[RKClient sharedClient] setBaseURL:base];
[[RKClient sharedClient] setAuthenticationType:RKRequestAuthenticationTypeHTTPBasic];
[[RKClient sharedClient] setCachePolicy:RKRequestCachePolicyNone];
RKRequest *request = [[RKClient sharedClient] get:@"/verify.json" delegate:self];
[request setCachePolicy:RKRequestCachePolicyNone];
}
I also noticed that if I put in the wrong password when first logging in and it comes back as a failure. If I then correct the password, it will always fail there after.
Upvotes: 3
Views: 575
Reputation: 818
Apparently Restkit stores some kind of cookie for authentication. In my case I could log out and log back in with the wrong password as long as the username stayed the same.
In my case I could solve the problem with:
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in cookieStorage.cookies)
{
[cookieStorage deleteCookie:cookie];
}
Which got rid of all stored cookies. I hope this will resolve your issue as well.
Upvotes: 1