superfell / zkSforce

Cocoa library for calling the Salesforce.com Web Services API
https://pocketsoap.com/osx/zksforce/
MIT License
76 stars 27 forks source link

OAuthDemo for iOS #50

Closed SteveDCronin closed 5 years ago

SteveDCronin commented 5 years ago

Simon;

I'm currently trying to implement zkSforce in an iPad app using OAuth.

Your OAuthDemo is macOS only and relies on 2 Mac-isms 1) [[NSWorkspace sharedWorkspace] openURL:url]; 2) [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

The first can be easily retro-fitted with: [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { //completion codes here }];

The second has me stumped... When I am authenticating for the first time I build the loginURL like so: NSString login = [NSString stringWithFormat:@"https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id=%@&redirect_uri=%@", [SALESFORCE_OAUTH_CLIENTID stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]], [SALESFORCE_OAUTH_CALLBACK stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]; NSURL url = [NSURL URLWithString:login];

If I then use the UIApplication openURL method shown above I'm not seeing how I can obtain the callback (NSString) that the macOS implementation obtains by using the 'ReplyEvent'...

Can you shed any light on how to complete the initial OAuth login on iOS? Thanks! Steve

SteveDCronin commented 5 years ago

So the answer is:

'url' that is passed in: [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { //completion codes here }];

is updated inside the completionHandler. All that is required is to read 'url' inside the completionHandler! Done!

superfell commented 5 years ago

Thats bizarre!

superfell commented 5 years ago

I'd of thought you'd want this https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app?language=objc