This is for Restkit v0.2.0 for iOS.
I am trying to use Windows Authentication by setting the default credentials for the HTTP client so that when the request's authentication is challenged it works.
I do that like this:
[[RKObjectManager sharedManager].HTTPClient setDefaultCredential:[NSURLCredential credentialWithUser:usr password:pass persistence:NSURLCredentialPersistenceForSession]];
Then I try to get my objects:
[[RKObjectManager sharedManager].router.routeSet addRoute:[RKRoute routeWithClass:[Applications class] pathPattern:@"portfolio" method:RKRequestMethodGET]];
[RKObjectManager.sharedManager getObjectsAtPath:@"portfolio" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSLog(@"It Worked: %@", [mappingResult array]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"It Failed: %@", error);
}];
But it's not working, I always get "It Failed" and the page says "invalid credentials".
So I started looking around and found out I need to be responding to the authentication challenge, but that is already being done. If I walk through the method that does it, my credentials are nil (0x00000000). The method I walk through is this one:
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
So I did some exploring and found out that the defaultCredentials is being set in this method:
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest...
But not this one, and this is the one being called:
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
So my credentials are never being set and I don't understand why. And especially why wouldn't it use an HTTPRequest and the HTTPClient connection and all that corresponding jazz?
Am I maybe calling the wrong methods? Is there a way to force it through the client?
Or is there another better way to set the credentials for all Requests?
Any help is appreciated! Thanks!