# Google Cloud Storage Integration

#### 1. Google Cloud Storage REST API

**Cloud Storage JSON REST API** based integration: [Cloud Storage JSON REST API Link](https://cloud.google.com/storage/docs/json_api)

---

**⚠️ Proxy Configuration:** If your server accesses the internet through a proxy, make sure to whitelist the following domains for Google Authentication and Storage access:\
\- **oauth2.googleapis.com**\
\- **storage.googleapis.com**

---

Start by navigating to Google APIs & Services: [Google APIs & Services Link](https://console.developers.google.com/projectselector/apis/credentials)\
**⚠️ Important:** Ensure the **Cloud Storage** is enabled at **Enabled APIs & services**. [Google API Library Link](https://console.cloud.google.com/apis/library)

![G api services](SMTP-Google-Mail-Integration/g_api_services.png)\
![Clopud storage api enable](Google-Cloud-Storage-Integration/clopud_storage_api_enable.png)

#### 1.1 Configure access through a Web Application OAuth client

Go to the **Credentials** menu, click on **Create Credentials**, and select **OAuth client ID**:\
![Create credentials](SMTP-Google-Mail-Integration/create_credentials.png)

• Select the application type: **Web application**.\
• Provide a unique name to identify your OAuth client (e.g., CrushFTP Integration).\
Then configure the following:\
• **Authorized JavaScript origins**: Add the base URL of your CrushFTP server (e.g., https<!-- -->://your-domain.com).\
• **Authorized redirect URIs**: This is the URL Google will redirect to after successful authorization. The Redirect URL must end with **?command=register_gdrive_api**

```

    http://127.0.0.1:9090/?command=register_gdrive_api
    or
    https://your.crushftp.domain.com/?command=register_gdrive_api
```

Finally, click the **Create** button.

![Credential config gdrive](SMTP-Google-Mail-Integration/credential_config_gdrive.png)

After the credentials are created, copy the **Client ID** and **Client Secret**.

![Client id secret](SMTP-Google-Mail-Integration/client_id_secret.png)

**⚠️ Note:** You can configure the **OAuth consent screen** by clicking the link above the **Authorized JavaScript origins** section:\
"The domains you enter in the fields below will be automatically added to your **OAuth consent screen** as **authorized domains**."\
Click the link to open the **OAuth consent screen** settings, complete the configuration, and authorize your **CrushFTP domain.**\
**Important**: After configuration, don’t forget to click **Publish App** at **Audience** page to make it active. Without publishing, the app will remain in **Testing** mode, which restricts access to authorized test users only.

**GStorage Remote Item Settings**:

Select the **GStorage** item type and click the **Get Refresh Token** button.\
**⚠️ Important**: To obtain the **Refresh Token**, the CrushFTP WebInterface’s host and port must match the **Redirect URL** specified in the **Google APIs & Services**-> **Credentials** -> **OAuth 2.0 Client IDs**. In our example, it was: http<!-- -->://127.0.0.1:9090 or https<!-- -->://your.crushftp.domain.com/

Enter the **Client ID** , **Client Secret**. Proceed with the authentication and authorization process.\
**⚠️ Important**: Be sure to sign in with the **Google Account** that has the **necessary permissions**, as configured in the **Google APIs & Services**-> **Credentials** -> **OAuth 2.0 Client IDs**. This will automatically configure the **User name** and **Password**.\
![Gdrive oauth form](GDriveSetup/gdrive_oauth_form.png)

If the domain is unverified, a warning message may appear. Click **Advanced** and choose to proceed:

![Not verified domain](SMTP-Google-Mail-Integration/not_verified_domain.png)

Click on the **Allow** button:

![Allow form](SMTP-Google-Mail-Integration/allow_form.png)

Provide the **Google Storage Bucket** and the path.

![Bucket and test](Google-Cloud-Storage-Integration/bucket_and_test.png)

#### 1.2. Configure access using a Service Account OAuth client

Create Credentials -> Service Account.\
![Service account](Google-Cloud-Storage-Integration/service_account.png)

Provide a name and continue.\
![Service account details](Google-Cloud-Storage-Integration/service_account_details.png)

Configure the service account access.\
![Storage account access](Google-Cloud-Storage-Integration/storage_account_access.png)

Click on the **Done** button.

Navigate to the newly created **Service Account**. Go to the **KEYS** tab. Click on the **Add KEY** button, and then select **Create new key**.\
![Service account new key](Google-Cloud-Storage-Integration/service_account_new_key.png)

Download the JSON file.\
![Service account private key](Google-Cloud-Storage-Integration/service_account_private_key.png)

**VFS configuration:**

Username: **google_jwt** -> Special user name for Service Account Access.\
Password: **<\<the JSON file content>>** -> It authenticates based on the provided JSON file.\
Provide the **bucket** and the path.\
It is done! Test the connection and save it!\
![Service acount vfs test](Google-Cloud-Storage-Integration/service_acount_vfs_test.png)

---

#### 2. Access through S3 REST API

Generate **Access key** and **Secret**. Got to [Google Console Cloud Link](https://console.cloud.google.com/) In the left sidebar of the dashboard, click on the **Google Cloud Storage** and then **Settings**.\
![Cloud storage sttings](Google-Cloud-Storage-Integration/cloud_storage_sttings.png)\
Select the Interoperability tab. If you haven't enabled it already, click on **Interoperable Access**. Now you should see an empty list and a **Create New Key** button. Click the button to create an **Access/Secret key** pair.

**Google Cloud S3 VFS configuration:**\
**1.**\
Domain: <\<Cloud Storage -> Settings -> INTEROPERABILITY -> Domain of **Storage URI** default is **storage.googleapis.com**>>\
Change the S3 default domain (s3.amazonaws.com) to the domain of Google Cloud Storage domain.

User name:**<\<Access Key>>**

Password:**<\<Secret>>**

Bucket:**<\<Google Cloud Storage Bucket Name>>**

**SHA256 enabled on signing (Signing Version 4)**:<\<Enabled>>\
**⚠️** **Signing version 4** must be enabled, as Google Cloud Storage does not support older signing versions.

![S3 vfs settings](Google-Cloud-Storage-Integration/s3_vfs_settings.png)\
**2.** Select **GStorage** Item type.\
Enable **S3 API** flag.

Domain:<\<Cloud Storage -> Settings -> INTEROPERABILITY -> Domain of **Storage URI** default is **storage.googleapis.com**>>\
Change the S3 default domain (s3.amazonaws.com) to the domain of Google Cloud Storage domain.\
User name: **<\<Access Key>>**\
Password: **<\<Secret>>**\
Bucket: **<\<Google Cloud Storage Bucket Name>>**\
**SHA256 enabled on signing (Signing Version 4)**:<\<Enabled>>\
**⚠️** **Signing version 4** must be enabled, as **Google Cloud Storage** does not support older signing versions.

![Gstroage s3 api vfs enabled](Google-Cloud-Storage-Integration/gstroage_s3_api_vfs_enabled.png)

More info about s3 VFS configuration: [S3 integration](S3-integration.md)
