# Getting Started with OAuth in CData Connectivity Solutions

**URL:** <https://community.cdata.com/t/getting-started-with-oauth-in-cdata-connectivity-solutions/134>\
**Category:** Getting started\
**Tags:** article, driver, oauth\
**Created:** [March 31, 2023, 4:35pm UTC](https://community.cdata.com/t/getting-started-with-oauth-in-cdata-connectivity-solutions/134 "2023-03-31T16:35:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerodj-cdata](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/jerodj-cdata/32/7_2.png) [@jerodj-cdata](https://community.cdata.com/u/jerodj-cdata)\
**Post date:** [March 31, 2023, 4:35pm UTC](https://community.cdata.com/t/getting-started-with-oauth-in-cdata-connectivity-solutions/134/1 "2023-03-31T16:35:37Z")

</div>

OAuth 2.0 is an authorization protocol that that allows an API client to have restricted access to user data on a web server. It is notably used by the APIs of prominent applications like Facebook, Google, GitHub and many more. OAuth is based on authentication scenarios, or “Grant Types” (flows) that let the resource owner or the user, without disclosing their credentials, share the resource server’s protected content. To accomplish this, an OAuth 2.0 server generates access tokens that client programs can use to gain access to restricted resources on behalf of the resource owner. OAuth 2.0 details can be found at **[oauth.net](http://oauth.net)** and **RFC 6749**.

In this article, we describe the various processes for performing OAuth authorization using CData connectivity solutions, focusing on the “Code” or the “Authorization Code” OAuth Grant Type since it is the most common among all the OAuth 2.0 grant types that you’ll encounter.

_NOTE:_ The instructions below refer to the **CData JDBC Driver for Salesforce** , but the principals can be used regardless of the data source or client application being used. You need the ability to use custom SQL queries to trigger some of the OAuth flows.

## Contents

- [(Optional) Creating a Custom OAuth Application in Salesforce](#customapp)
- [Performing OAuth with Desktop Applications](#desktop)
- [Performing OAuth with Web Applications](#web)
- [Performing OAuth with Headless Machines](#headless)

## (Optional) Creating a Custom OAuth App in Salesforce

The following describes the step-by-step process of how you can create a custom application in Salesforce:

1. Login to your Salesforce account  
 ![f94a7f3e-fc08-4ba9-a6ec-194be33af05b.png](https://us1.discourse-cdn.com/cdata/original/1X/4bb7b686e545e3dca8f4aebf0e72a684e2035af2.png)
2. Go to “Setup” at the top right corner of the Salesforce account
3. Enter “Apps” in the Quick Find box, go to “App Manager” from the dropdown and then click on “New Connected App” the link to create an application  
 ![ff7d792c-0a02-4e03-a368-cfb19d22ccb7.png](https://us1.discourse-cdn.com/cdata/original/1X/673397f6cb77176f2e5e1a1e7d212de3ee70e655.png)
4. In the **New Connected App** section, enter “Connected App Name”, “API Name”, “Contact Email”  
 ![397a868b-e4a5-4a04-b248-c16684b959bc.png](https://us1.discourse-cdn.com/cdata/original/2X/7/70ceb7c021e8e498568d9a35396d80a0fc281e0e.png)
5. Enable the API (Enable OAuth Settings) checkbox and enter the “Callback URL” and select the required OAuth scope of permissions that your application should request from the user. Example: Scopes such as ‘_refresh\_token’, 'offline\_access_’ permission is required to get a refresh token and perform requests at any time. To get data, **Full Access (full)** or **API (Manage User Data via APIs)** are to be used  
 ![501275d1-83f1-4ff8-a0ce-addabc03cab9.png](https://us1.discourse-cdn.com/cdata/original/2X/0/0fa35dd3e5cb21b5623ac41065df516c800122d2.png)
6. Click on “Save” to create the customer OAuth application
7. Under API (Enable OAuth Settings) section of the New Connected app, click on “Manage Consumer Details” to obtain the “Client ID” (Consumer Key) and “Client Secret” (Consumer Secret) which we use later to connect to this application using the CData Salesforce JDBC driver  
 ![e5062737-cbe2-4bec-9d24-2a6b0dee1391.png](https://us1.discourse-cdn.com/cdata/original/2X/0/005d5c350ddac2fb64322a4b50d9e759274a791d.png)

 ![12060064-b67c-4951-8e13-f7467f6c9d7a.png](https://us1.discourse-cdn.com/cdata/original/1X/5a5221253c666e162ee10bc6688ab793f69f130d.png)

## Performing OAuth with Desktop Applications

### For Embedded OAuth Credentials

For many data sources, CData provides embedded OAuth credentials that simplify OAuth Desktop Authentication.

To connect with the Embedded OAuth credentials using the Salesforce JDBC Driver, the user needs to follow the given steps:

1. Download and install the CData JDBC Driver
2. Follow the installation path to the Salesforce JDBC Driver and open the “lib” folder.  
Path (example): C:\Program Files\CData\CData JDBC Driver for Salesforce 2022\lib
3. Open the executable JAR file “cdata.jdbc.salesforce.jar” to open the JDBC URL configuration wizard
4. Set the “AuthScheme” to OAuth and set “InitiateOAuth” to GETANDREFRESH
5. Click on “Test Connection”
6. The user gets rerouted to Salesforce login page where they need to provide all the required credentials (Username and Password)
7. Once the correct credentials are entered, “Salesforce Authorization Successful” screen pops up  
 ![9115ca23-4c5c-44ac-a6bd-d10dfb44a33e.png](https://us1.discourse-cdn.com/cdata/original/1X/27cdde24aedff363d0237766ce8c4d850ea3b907.png)
8. The JDBC driver alerts that the connection was successful (refer below):  
 ![1b74cac4-f019-4dbe-a2b0-8f381cfbdf8d.png](https://us1.discourse-cdn.com/cdata/original/1X/9b4bb9af7288064c2b05075ace20b6a6a4ffc9b6.png)

### For Connecting with the Custom OAuth Application (Desktop)

1. Follow steps 1 - 4 mentioned in “For Embedded OAuth” from Desktop Authentication

2. Additionally, along with setting “Initiate OAuth” as GETANDREFRESH, enter the “Client ID” and “Client Secret” details saved from your custom OAuth application (see “Creating Custom OAuth Application in Salesforce” above)  

3. When you connect, the driver opens the OAuth endpoint in your default browser. Log in and grant permissions to the application.  

4. The driver then completes the OAuth process as follows:
