# Setting up Snowflake OAuth

This section outlines the steps required to create an integration and use OAuth to connect to Snowflake.

### 1. Prerequisites

* Whitelist Inforiver IPs in the Azure SQL firewall. [Learn more about whitelisting Inforiver IPs](https://docs.inforiver.com/introduction-to-inforiver/get-started/inforiver-writeback-matrix-prerequisites/whitelist-inforiver-ips).
* For Saas customers, <https://addons.inforiver.com> should be whitelisted in the firewall so the application can reach the server configured.

### 2. Creating an integration in Snowflake

**STEP 1:** Use the ACCOUNTADMIN role to log in to the Snowflake web interface. Navigate to Projects -> Worksheets -> Click the Add icon at the top left -> Select SQL worksheet.

**STEP 2:** Create an OAuth Security Integration by executing the query:

<pre class="language-sql"><code class="lang-sql">CREATE SECURITY INTEGRATION MY_INTEGRATION_NAME
TYPE = OAUTH
ENABLED = TRUE
OAUTH_CLIENT = CUSTOM
OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'
<strong>OAUTH_REDIRECT_URI = '&#x3C;Redirect link>'
</strong>OAUTH_ISSUE_REFRESH_TOKENS = TRUE
OAUTH_REFRESH_TOKEN_VALIDITY = 86400; -- set OAUTH Refresh token validity from 1 to 90 days (about 3 months) in seconds 
</code></pre>

**STEP 3:** Fetch details for client configuration. You will need to enter these details while creating a Snowflake destination or connection in Inforiver.

Retrieve the Client ID and Client secret:

```sql
SELECT SYSTEM$SHOW_OAUTH_CLIENT_SECRETS( 'MY_INTEGRATION_NAME');
//OAUTH_CLIENT_ID => Client ID field in Inforiver console
//OAUTH_CLIENT_SECRET => Client Secret field in Inforiver console
```

Get the Authorization and Token URL:

```sql
DESC SECURITY INTEGRATION MY_INTEGRATION_NAME;
//OAUTH_AUTHORIZATION_ENDPOINT => Authorization URL field in Inforiver console
//OAUTH_TOKEN_ENDPOINT => Token URL field in Inforiver console
```

### 3. Using OAuth to create a destination or connection in Inforiver

**STEP 1:** Enter the **Integration Name**, **Client ID**, **Client Secret**, **Authorization URL**, and **Token URL** required for OAuth in the Inforiver console. Refer to the [previous section ](#id-1.-creating-an-integration-in-snowflake)to learn more about fetching the integration details from Snowflake. Click **Connect**.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FycuICc5Ht0R9YIyqJnzv%2Fimage.png?alt=media&#x26;token=596afa3b-463c-4ade-a0ac-26e5861bcadd" alt=""><figcaption><p>Enter integration details for Snowflake</p></figcaption></figure>

You will be redirected to the Snowflake login page, where you need to enter your Username and Password to connect.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FYo8ECNq3nVpXGVlGA9UR%2Fimage.png?alt=media&#x26;token=fd3b2f1e-be7f-4ff1-af14-47d254e60c7a" alt="" width="375"><figcaption><p>Snowflake Sign in</p></figcaption></figure>

### 4. Enter Account/DB/Schema/Warehouse details

After specifying the integration details for OAuth and signing into Snowflake, you will need to enter details in the section highlighted in the image:

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FACejBnGeoNH1QJLQgphp%2Fimage.png?alt=media&#x26;token=1b4cb5a0-122b-4e36-95f0-cb323bc72f7c" alt="" width="563"><figcaption></figcaption></figure>

* **Account**: Enter the name of your Snowflake server. Example: https\://\<account>.snowflakecomputing.com/
* **Database and Schema:** Snowflake Database and schema name where the writeback table will be created.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Fg9r5FCEjRqfbRkMpnVpS%2Fimage.png?alt=media&#x26;token=74fccdfa-3ed4-42ab-8504-9598b6bcf79a" alt=""><figcaption><p>Snowflake database and schema</p></figcaption></figure>

* **Warehouse:** The Snowflake compute warehouse.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FMJ2Pa0lsrfHY4TeSHmVB%2Fimage.png?alt=media&#x26;token=80f58329-8490-4f30-9aac-8b885beb1a5b" alt=""><figcaption><p>Snowflake warehouses</p></figcaption></figure>

* **Role**: The user role associated with the Snowflake username.  Ensure this role has “USAGE” and “CREATE TABLE” permissions. This is mandatory to be able to writeback from Inforiver to Snowflake.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FyAGhdVDew3r6yOtrQV0U%2Fimage.png?alt=media&#x26;token=6d1de272-5ffe-48cb-a863-dc574fb3e5ec" alt=""><figcaption><p>Snowflake roles</p></figcaption></figure>
