[SalesForce] Using a cloudforce.com login page for OAuth with a hybrid mobile app

Is it possible to use a cloudforce.com login page, e.g. https://example.cloudforce.com, to authenticate users with the PhoneGap OAuth plugin?

The plugin is called from javascript using:

PhoneGap.exec(success, fail, "com.salesforce.oauth", "authenticate", [JSON.stringify(oauthProperties)]);

Passing the login domain in oauthProperties would seem to be the place to set it. I found this changeset which removed oauthLoginDomain from oauthProperties: https://github.com/forcedotcom/SalesforceMobileSDK-Shared/commit/2bb43033f2806cb5b827dd940c42eab09a7c3276

Is oauthLoginDomain still supported by the plugin, or is there a new way of doing this?

Best Answer

Edited to reflect the fact that Salesforce Mobile SDK is in play

The user can add a custom login host in the settings for their app (on iOS, from the home screen, Settings | Your App | Custom Host) and select it as the current login host.

So, the user can, in principle, add example.cloudforce.com as a custom host and select it for use. You can also add My Domain hostnames such as mycompany.my.salesforce.com - useful to have SAML work during the login.

I can't guarantee it will work with example.cloudforce.com in particular, but it certainly does work with dreamevent.my.salesforce.com - I've tried that login URL in the desktop Chatter app that uses the same OAuth flow.

Now, if you want to do all this without the user getting involved, it looks like you can edit shared/Classes/Security/SFAccountManager.m - lines 45, 46 in the current Mobile SDK for iOS:

// Value to use for login host if user never opens the app settings.
NSString * const kDefaultLoginHost = @"login.salesforce.com";

In the current Android version, lines 100, 101 of native/SalesforceSDK/src/com/salesforce/androidsdk/auth/OAuth2.java:

// Login URLs / paths
public static final String DEFAULT_LOGIN_URL = "https://login.salesforce.com";
Related Topic