Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. 1) I have a HOME screen in my iOS native application.
  2. 2) From there I have to navigate to Salesforce login screen.
  3. 3) User will enter credentials and Salesforce will validate it.
  4. 4) Once logged in success then it will back to my HOME screen with token/sessionID.
  5. 5) That token/sessionID I will use internally in my application.
  6.  
  7. - (IBAction)login:(UIButton*)sender {
  8.  
  9. NSString *strClientID = @"2kN3Bn17hv5A1f.3QFK.....";
  10. NSString *strCallbackURI = @"https://localhost:0000/signin-salesforce";
  11.  
  12. NSString *kIdentifier = @"com.salesforce.ios";
  13.  
  14. SFOAuthCredentials *creds = [[SFOAuthCredentials alloc] initWithIdentifier:kIdentifier clientId:strClientID encrypted:YES];
  15. creds.redirectUri = strCallbackURI;
  16.  
  17. _oauthCoordinator = [[SFOAuthCoordinator alloc] initWithCredentials:creds];
  18. // _oauthCoordinator.scopes = [NSSet setWithObjects: @"web", nil]; /* If I pass scopes then I'm getting "Invalid scopes even I enabled same scopes in salesforce as a connected app" */
  19. _oauthCoordinator.delegate = self;
  20. [_oauthCoordinator authenticate];
  21. }
  22.  
  23. #pragma mark - SFOAuthCoordinatorDelegate
  24.  
  25. - (void)oauthCoordinator:(SFOAuthCoordinator *)manager didBeginAuthenticationWithView:(UIWebView *)webView {
  26.  
  27. CGRect newFrame = self.view.frame;
  28. newFrame.origin.y +=64;
  29. webView.frame = newFrame;
  30. [self.view addSubview:webView];
  31. }
  32.  
  33. - (void)oauthCoordinatorDidAuthenticate:(SFOAuthCoordinator *)coordinator authInfo:(SFOAuthInfo *)info
  34. {
  35. [self.oauthCoordinator.view removeFromSuperview];
  36. NSLog(@"authType = %d",info.authType);
  37. NSLog(@"accessToken = %@",coordinator.credentials.accessToken);
  38. NSLog(@"refreshToken = %@",coordinator.credentials.refreshToken);
  39. NSLog(@"instanceUrl = %@",[coordinator.credentials.instanceUrl description]);
  40. NSLog(@"issuedAt = %@",[coordinator.credentials.issuedAt descriptionWithLocale:[NSLocale currentLocale]]);
  41. NSLog(@"userId = %@",coordinator.credentials.userId);
  42. NSLog(@"organizationId = %@",coordinator.credentials.organizationId);
  43. NSLog(@"communityId = %@",coordinator.credentials.communityId);
  44. NSLog(@"legacyIdentityInformation = %@",coordinator.credentials.legacyIdentityInformation);
  45. NSLog(@"activationCode = %@",coordinator.credentials.activationCode);
  46. }
  47.  
  48. - (void)oauthCoordinator:(SFOAuthCoordinator *)coordinator didFailWithError:(NSError *)error authInfo:(SFOAuthInfo *)info
  49. {
  50.  
  51. [self.oauthCoordinator.view removeFromSuperview];
  52. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error %d", error.code]
  53. message:error.localizedDescription
  54. delegate:nil
  55. cancelButtonTitle:@"OK"
  56. otherButtonTitles:nil];
  57. [alert show];
  58. }
  59.  
  60. Output log
  61. 2014-12-19 12:55:45.946 SampeSalesforce[24576:607] authType = 1
  62. 2014-12-19 12:55:45.947 SampeSalesforce[24576:607] accessToken = MAQOGHGMlDR.keKCErM5MAIHJI65S5ABF646DBB89AB767FBAB77575l2Dbf4Z6UkdYnE8x70BoXLzP
  63. 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] refreshToken = (null)
  64. 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] instanceUrl = (null)
  65. 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] issuedAt = (null)
  66. 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] userId = (null)
  67. 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] organizationId = (null)
  68. 2014-12-19 12:55:45.949 SampeSalesforce[24576:607] communityId = (null)
  69. 2014-12-19 12:55:45.949 SampeSalesforce[24576:607] legacyIdentityInformation = (null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement