Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use basic auth with RestKit's getObject?

Tags:

ios

restkit

I tried the following to set the basic auth username and password, but it does not seem to be passing the basic auth in the request..

secureManager = [[RKObjectManager objectManagerWithBaseURL:@"http://localhost:3000"] retain];

secureManager.client.username = uname;
secureManager.client.password = pwd;


RKObjectLoader *loader = [svc getObject:user delegate:self];

loader.userData = [NSNumber numberWithInt:RequestLogin];

UPDATE: found my problem, I needed to add the following snippet

secureManager.client.forceBasicAuthentication = YES;
like image 354
MonkeyBonkey Avatar asked Sep 17 '11 13:09

MonkeyBonkey


1 Answers

You can grab an instance of the underlying RKClient before you make your request and set the Username and Password like so:

// Set the Username and Password
[RKObjectManager sharedManager].client.username = @"username"; 
[RKObjectManager sharedManager].client.password = @"letmein";

// Make our Request
[[RKObjectManager sharedManager] getObject:user mapResponseWith:mapping delegate:self];

As MonkeyBonkey points out in the comments, you may need to force the authentication using a flag:

[RKObjectManager sharedManager].client.forceBasicAuthentication = YES;
like image 58
Suhail Patel Avatar answered Sep 18 '22 03:09

Suhail Patel