Self-Login to Salesforce API on iPhone?

I am using Salesforce api and I want to automatically log in (hardcode name and password). I am using the REST API, and here is the login code that shows the login form:

- (void)login { SFOAuthCredentials *credentials = [[[SFOAuthCredentials alloc] initWithIdentifier:remoteAccessConsumerKey] autorelease]; credentials.protocol = @"https"; credentials.domain = OAuthLoginDomain; credentials.redirectUri = OAuthRedirectURI; self.coordinator = [[[SFOAuthCoordinator alloc] initWithCredentials:credentials] autorelease]; self.coordinator.delegate = self; NSLog(@"%@",self.coordinator); // remove this line if we want to cache the key, and use refresh flow //effectively, we are saying, purge the old login and re-authenticate each time [self.coordinator revokeAuthentication]; //now let authenticate [self.coordinator authenticate]; } 

What do I want for automatic login (do not ask for a username or password), where do I insert a username and password?

+2
source share
3 answers
  • Include zkforce in your project
  • Add these files to your project
 #import "ZKSforce.h" #import "FDCServerSwitchboard.h" #import "ZKLoginResult.h" 
  • Add this code to .m
  NSString *username = NSString *password = NSString *token = @"amnwcg24Uu5IenCvAJM5HgRq"; NSString *passwordToken = [NSString stringWithFormat:@"%@%@", password, token]; [[FDCServerSwitchboard switchboard] loginWithUsername:username password:passwordToken target:self selector:@selector(loginResult:error:)]; 
  • See result
 - (void)loginResult:(ZKLoginResult *)result error:(NSError *)error { if (result && !error) { NSLog(@"Hey, we logged in!"); //[self fetchAccounts]; } else if (error) { NSLog(@"An error occurred while trying to login."); } } 
0
source

Salesforce toolkit for iOS page shows an example of using ZKSForce, which returns a token that can be used by REST API calls, see the document here

The REST API typically uses the OAuth token, which eliminates the need for the user to enter their username and password into a third-party system such as yours. They enter the username once, and the system updates the token to remain in the system (this is a simplified explanation). Either use OAuth, which is the correct way with a mobile phone and REST API, or use the session identifier from the old-style SOAP login request.

+3
source

Quick google and I found this - https://github.com/superfell/zkSforce

Did not try though!

+1
source

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


All Articles