4

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!

Wain
  • 118,658
  • 15
  • 128
  • 151
Jordan
  • 141
  • 1
  • 8
  • Same problem. Did you find solution ? – OldFox Jul 03 '13 at 14:05
  • It is a bug in RestKit and Blake Watters (author of RestKit) confirmed it. You can find our conversation in the RestKit google group. A temporary fix is just to modify your local copy of RKObjectManager to call the method to set the credentials. In requestWithMethod add a line that sets the defaultCredentials of the operation. I can provide more information if this is not helpful, let me know in a comment, but I won't have access to the code that I ran into this problem with for a week. – Jordan Jul 04 '13 at 16:32

0 Answers0