mike4aday / SwiftlySalesforce

The Swift-est way to build native mobile apps that connect to Salesforce.
MIT License
136 stars 43 forks source link

Implementation in ipad Swift Playground. AuthenticationError #149

Closed unoctanium closed 1 year ago

unoctanium commented 1 year ago

Hi,

I tried to implement a test app in Swift Playgrounds, following your example code. Problem: if Salesforce.connect is run, a new popup opens in the app:

MyApp wants to use "salesforce.com" to sign in This allows the app and website to share information about you. Cancel , Continue

Pressing continue opens new window: Title: login.salesforce.com Window content: a document icon with a question mark, the thext „authorize“, the text „data - 71 bytes“, a buttom „open in“ (which would let me open the document in a lot of useless apps) and a cancel button.

Pressing cancel reslts in an error message: The operation couldn‘t be completed. (com.apple.AuthenticationServices.WebAuthenticationSession error 1.)

Btw: the contents of the 71 byte answer is: error=invalid_client_id&error_description=client%20identifier%20invalid

and Salesforce.json is in place and correctly configured. I copied the consumer key and the callbackURL from my salesforce connected app

and in salesforce the settings for the connected app are:

Selected OAuth Scopes: Full access (full) Perform requests at any time (refresh_token, offline_access)

callbackURL: connapp://callback

Seems like I have a problem with OAuth? Do you have any idea how to fix that?

mike4aday commented 1 year ago

Hi @unoctanium I have never tried Swiftly Salesforce in the iPad Playgrounds app. Swiftly Salesforce uses ASWebAuthenticationSession with OAuth, which launches Safari to display Salesforce's login page. Can you "open in..." Safari? I don't know if that would even work since Swiftly Salesforce has to parse the callback URL from Salesforce.

unoctanium commented 1 year ago

Hi @mike4aday Thank you for the hint. This issue can be marked as completed. Here is how I resolved:

In the Salesforce.json, I added a line:

"authorizingHost": "<mySite>.my.salesforce.com"

Where <mySite> is the beginning of the URL of my dev-environment.

It seems like we have to use different authorizing hosts, depending on how we want to connect:

At least in my case that solved the issue.

mike4aday commented 1 year ago

@unoctanium FYI even if you use the default authorizing host, login.salesforce.com: when the Salesforce-hosted login form is displayed, you can click "Forgot Your Password" and then "Sandbox Login" -- or "Use Custom Domain" and then enter a 'My Domain' name -- to use non-default authorizing hosts.