Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) I have a HOME screen in my iOS native application.
- 2) From there I have to navigate to Salesforce login screen.
- 3) User will enter credentials and Salesforce will validate it.
- 4) Once logged in success then it will back to my HOME screen with token/sessionID.
- 5) That token/sessionID I will use internally in my application.
- - (IBAction)login:(UIButton*)sender {
- NSString *strClientID = @"2kN3Bn17hv5A1f.3QFK.....";
- NSString *strCallbackURI = @"https://localhost:0000/signin-salesforce";
- NSString *kIdentifier = @"com.salesforce.ios";
- SFOAuthCredentials *creds = [[SFOAuthCredentials alloc] initWithIdentifier:kIdentifier clientId:strClientID encrypted:YES];
- creds.redirectUri = strCallbackURI;
- _oauthCoordinator = [[SFOAuthCoordinator alloc] initWithCredentials:creds];
- // _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" */
- _oauthCoordinator.delegate = self;
- [_oauthCoordinator authenticate];
- }
- #pragma mark - SFOAuthCoordinatorDelegate
- - (void)oauthCoordinator:(SFOAuthCoordinator *)manager didBeginAuthenticationWithView:(UIWebView *)webView {
- CGRect newFrame = self.view.frame;
- newFrame.origin.y +=64;
- webView.frame = newFrame;
- [self.view addSubview:webView];
- }
- - (void)oauthCoordinatorDidAuthenticate:(SFOAuthCoordinator *)coordinator authInfo:(SFOAuthInfo *)info
- {
- [self.oauthCoordinator.view removeFromSuperview];
- NSLog(@"authType = %d",info.authType);
- NSLog(@"accessToken = %@",coordinator.credentials.accessToken);
- NSLog(@"refreshToken = %@",coordinator.credentials.refreshToken);
- NSLog(@"instanceUrl = %@",[coordinator.credentials.instanceUrl description]);
- NSLog(@"issuedAt = %@",[coordinator.credentials.issuedAt descriptionWithLocale:[NSLocale currentLocale]]);
- NSLog(@"userId = %@",coordinator.credentials.userId);
- NSLog(@"organizationId = %@",coordinator.credentials.organizationId);
- NSLog(@"communityId = %@",coordinator.credentials.communityId);
- NSLog(@"legacyIdentityInformation = %@",coordinator.credentials.legacyIdentityInformation);
- NSLog(@"activationCode = %@",coordinator.credentials.activationCode);
- }
- - (void)oauthCoordinator:(SFOAuthCoordinator *)coordinator didFailWithError:(NSError *)error authInfo:(SFOAuthInfo *)info
- {
- [self.oauthCoordinator.view removeFromSuperview];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error %d", error.code]
- message:error.localizedDescription
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- }
- Output log
- 2014-12-19 12:55:45.946 SampeSalesforce[24576:607] authType = 1
- 2014-12-19 12:55:45.947 SampeSalesforce[24576:607] accessToken = MAQOGHGMlDR.keKCErM5MAIHJI65S5ABF646DBB89AB767FBAB77575l2Dbf4Z6UkdYnE8x70BoXLzP
- 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] refreshToken = (null)
- 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] instanceUrl = (null)
- 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] issuedAt = (null)
- 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] userId = (null)
- 2014-12-19 12:55:45.948 SampeSalesforce[24576:607] organizationId = (null)
- 2014-12-19 12:55:45.949 SampeSalesforce[24576:607] communityId = (null)
- 2014-12-19 12:55:45.949 SampeSalesforce[24576:607] legacyIdentityInformation = (null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement