Using OAuth
Salesforce supports OAuth 2.0 authentication, letting you access data securely without having to reveal user name and password credentials.
You can configure the connector to use the client credentials authentication flow to establish an OAuth connection.
To connect using client credentials, you must specify the following connection properties:
OAuth Client IDOAuth Client Secret
You provide the configuration information to the connector in the connection URL. For more information about the syntax of the connection URL, see Building the Connection URL.
Before setting the connector connection properties, you must configure your application to integrate with Salesforce and then obtain the necessary values for the connector connection properties:
- In your application, select an appropriate OAuth 2.0 authentication flow that Salesforce supports.
- In the Force.com administration console, configure an external client app for your application and obtain a Consumer Key and Consumer Secret, which is also known as a OAuth Client ID and OAuth Client Secret.
For detailed information about setting up authorization using OAuth 2.0, see "Set Up Authorization" in the Force.com REST API Developer Guide: http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm.
Example Using the Client Credentials
The following is an example connection URL for connecting to Salesforce using the Client Credentials:
jdbc:salesforce://localhost;ClientId="1KLcQce8MYQA9zLUnqEoSAoScsS_JPXL_szVVqzLPm3HQUFIbV_u8YxZZBbL8F;ClientSecret=8MYQA9zLUnqEoSAu30GGvAUR5kHWZ7l0t;O;URL=https://na11.salesforce.com
jdbc:salesforce://localhost;ClientId="1KLcQce8MYQA9zLUnqEoSAoScsS_JPXL_szVVqzLPm3HQUFIbV_u8YxZZBbL8F;ClientSecret=8MYQA9zLUnqEoSAu30GGvAUR5kHWZ7l0t;OAuthTokenEndpoint=https://na11.salesforce.com/services/oauth2/token
The following code demonstrates how to set connection properties to use an Access Token in establishing an OAuth connection:
// --- DEFINE PROPERTIES FOR THE CONNECTION ---
Properties ConnectionProperties = new Properties();
// ClientId is the "Consumer Key" that Salesforce registers for the application.
String clientId = "1KLcQce8MYQA9zLUnqEoSAoScsS_JPXL_szVVqzLPm3HQUFIbV_
u8YxZZBbL8F";
// ClientSecret is the "Consumer Secret" that Salesforce registers for the application.
String clientSecret = "e8MYQA9zLUnqEoSAu30GGvAUR5kHWZ7l0t";
// URL is the hostname of your Salesforce instance.
// By default, the connector will set the OAuthTokenEndpoint to URL + “/services/oauth2/token”
String url = "https://na11.salesforce.com";
// Alternatively, you can set the OAuthTokenEndpoint property directly.
String oauthTokenEndpoint = “https://na11.salesforce.com/services/oauth2/token";
ConnectionProperties.setProperty("ClientId", clientId);
ConnectionProperties.setProperty("ClientSecret", clientSecret);
ConnectionProperties.setProperty(“URL”, url);
ConnectionProperties.setProperty(“OAuthTokenEndpoint”, oauthTokenEndpoint);
// --- END PROPERTIES ---