Menu
Simba Technologies
Simba Technologies

Simba Salesforce JDBC Driver with SQL Connector 2.1.18
Installation and Configuration Guide

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 driver to use an Access Token or a Refresh Token to establish an OAuth connection.

To connect using an Access Token, you must specify the following connection properties:

  • AccessToken
  • Endpoint

To connect using a Refresh Token, you must specify the following connection properties:

  • RefreshToken
  • ClientID
  • Endpoint

You provide the configuration information to the driver in the connection URL. For more information about the syntax of the connection URL, see Building the Connection URL.

Before setting the driver connection properties, you must configure your application to integrate with Salesforce and then obtain the necessary values for the driver connection properties:

  1. In your application, select an appropriate OAuth 2.0 authentication flow that Salesforce supports.
  2. In the Force.com administration console, configure a connected app for your application and obtain a Consumer Key, which is also known as a Client ID.
  3. Using the Consumer Key and any other required parameters, obtain the instance URL (to use as part of the Endpoint setting) and the Access Token or Refresh Token. Depending on the authentication flow that you selected, you might also need to obtain an authorization code.

    Note:

    If you are connecting to a sandbox system, you need to set the Endpoint to the sandbox URL instead.

Note:

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 an Access 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();

// Set a variable for the Access Token received from

// Salesforce (using the Web Server Authentication Flow).

String AccessToken = "c6ssMR0.0AJ1iOkXV5040A3km1JfJ0yloo03ylaWDdYS06aWE0xDA56JCf9hqomYIF1c3VKIH3";

// The Endpoint property contains the Instance URL

// received from Salesforce. The endpoint should use the

// following form:

// https://[Instance].salesforce.com/services/Soap/u/46.0

String InstanceURL = "https://na11.salesforce.com";

String ServiceEndpoint = InstanceURL + "/services/Soap/u/46.0";

ConnectionProperties.setProperty("AccessToken", AccessToken);

ConnectionProperties.setProperty("Endpoint", ServiceEndpoint);

// --- END PROPERTIES ---

Example Using a Refresh Token

The following code demonstrates how to set connection properties to use a Refresh Token in establishing an OAuth connection.

// --- DEFINE PROPERTIES FOR THE CONNECTION ---

Properties ConnectionProperties = new Properties();

// Set a variable for the Refresh Token received from

// Salesforce (using the Web Server Authentication Flow).

String RefreshToken = "8qLdDkL1nqDpYqN4tRUCDO2.4fsMIYYsIn_MCPt.i3";

// Set a variable for the Access Token received from

// Salesforce (using Web Server Authentication Flow).

// Setting an Access Token is optional when using a

// Refresh Token.

// The driver uses the Refresh Token to get a new Access

// Token whenever the Access Token expires.

String AccessToken = "xZ.iKtGi0ztu30GGvAUR5kHWZ7l0t.5WGW5IGkg5y7W5.VJJNtwIOxXT.fDAOYDG3vyDu.AT7Di3";

// The ClientId is the "Consumer Key" that Salesforce

// registers for the application.

String ClientId = "1KLcQce8MYQA9zLUnqEoSAoScsS_JPXL_szVVqzLPm3HQUFIbV_u8YxZZBbL8F";

// The Endpoint property contains the Instance URL

// received from Salesforce. The Endpoint should use

// the following form:

// https://[Instance].salesforce.com/services/Soap/u/46.0

String InstanceURL = "https://na11.salesforce.com";

String ServiceEndpoint = InstanceURL + "/services/Soap/u/46.0";

ConnectionProperties.setProperty("RefreshToken", RefreshToken);

// Setting an Access Token is optional when using a

// Refresh Token.

ConnectionProperties.setProperty("AccessToken", AccessToken);

ConnectionProperties.setProperty("ClientId", ClientId);

ConnectionProperties.setProperty("Endpoint", ServiceEndpoint);

// --- END PROPERTIES ---