How to use basic auth with RestKit getObject?

I tried the following to set the base username and password for authorization, but it does not seem to pass 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; 
+6
source share
1 answer

You can grab an instance of the underlying RKClient before making your request, and set Username and Password as follows:

 // 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 authentication using the flag:

 [RKObjectManager sharedManager].client.forceBasicAuthentication = YES; 
+10
source

Source: https://habr.com/ru/post/897525/


All Articles