> ## Documentation Index
> Fetch the complete documentation index at: https://docs.forge.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Drive API

> Use a Resource Gateway to allow one Drive metadata read and block another.

Route two read-only Google Drive API requests through Forge. One returns metadata
for a synthetic file. Forge blocks the other before it reaches Google Drive.

## Prepare the sandbox

* Use an online [Resource Gateway](https://docs.forge.ai/resources/resource-gateways.md) that can reach
  `www.googleapis.com:443`.
* Use an approved test app and a dedicated test Drive account. Request a
  short-lived Google OAuth access token with the
  `https://www.googleapis.com/auth/drive.file` scope. [Drive API scopes](https://developers.google.com/workspace/drive/api/guides/api-specific-auth)
* Create two synthetic files through that app and copy their file IDs. Use the
  same app and account for the rest of the test.

## Configure the Resource and credential

1. Open **Policies → Resources** and choose **New resource**.
2. Name the Resource `Google Drive API sandbox`. Choose **HTTP**, set the host
   to `www.googleapis.com` and the port to `443`, then turn on **Use HTTPS**.
3. Assign the Resource Gateway and save. Leave **Automatic routing** off for
   the first run.
4. Open **Credentials** and add a **Bearer token** with the Google access
   token. Expand **Credential assignment**, select the test user, and leave
   **Use for everyone else** off.
5. Run **Test connection**. Verify access to the Drive files with the requests
   below.

The Gateway adds the Google bearer token after policy allows a request. Use
**Bearer token** for this short test and replace the Google access token after
it expires. Forge's **OAuth temporary access** uses the client credentials grant.
Google's user authorization flow renews access with a refresh token. [Forge credential methods](https://docs.forge.ai/resources/credentials-and-identity.md) · [Google OAuth token refresh](https://developers.google.com/identity/protocols/oauth2/web-server#offline)

## Block one file read

Run both requests in [Verify direct access](#verify-direct-access) before you
create the policy. Both requests should return `200` with the corresponding
file IDs.

1. Choose **New policy → Resource policy** and name it `Block sandbox Drive file`.
2. Scope the policy to `Google Drive API sandbox`.
3. Set **Condition type** to **Match all** and add both conditions.
   * **HTTP method** equals `GET`.
   * **HTTP path** equals `/drive/v3/files/BLOCKED_FILE_ID`. Replace
     `BLOCKED_FILE_ID` with the second file's ID.
4. Set the action to **Block** and the user message to
   `This sandbox Drive file is blocked.`
5. Set enforcement to **Enforce**, enable the policy, and save.

This policy matches the exact file metadata endpoint path. It also matches
requests for that file at the same path with query parameters. [HTTP policy fields](https://docs.forge.ai/resources/protocols/http.md)

## Verify direct access

Open **Connect directly** on the Resource page. Download the trust certificate
and select **Generate access**. Substitute your gateway hostname and file IDs
in the commands. Enter the short-lived Forge token when prompted.

```bash theme={"system"}
gateway='https://resources.example.com'
allowed_id='REPLACE_WITH_FIRST_FILE_ID'
blocked_id='REPLACE_WITH_SECOND_FILE_ID'

printf '%s' 'Forge access token: ' >&2
read -rs FORGE_ACCESS_TOKEN
printf '\n' >&2

for file_id in "$allowed_id" "$blocked_id"; do
  printf 'header = "Proxy-Authorization: Bearer %s"\n' "$FORGE_ACCESS_TOKEN" |
    curl --config - --silent --show-error --include \
      --cacert forge-resource-ca.pem \
      "$gateway/drive/v3/files/$file_id?fields=id,name"
done
unset FORGE_ACCESS_TOKEN
```

The first request returns `200` with the synthetic file's ID and name. The
second returns `403` with the Forge policy ID and the message you set. In
**Live → Resources**, filter to `Google Drive API sandbox` and check the
caller, path, and **Allow** and **Block** outcomes. [Drive files.get](https://developers.google.com/workspace/drive/api/reference/rest/v3/files/get) · [Resource Activity](https://docs.forge.ai/resources/activity-and-approvals.md)

## Verify automatic routing and MCP

For a test device that already has active [automatic routing](https://docs.forge.ai/resources/automatic-routing.md)
and trusts the organization inspection CA, turn on **Automatic routing** for the
Resource. Repeat the same two GET requests in fresh connections to
`https://www.googleapis.com` using the device's managed identity. Omit the
`Proxy-Authorization` header. Check the same outcomes and the device in
**Live → Resources**.

The device route matches the hostname. `www.googleapis.com` also hosts other
Google APIs, so use a dedicated test device for this check.

To test both interfaces, use an approved Drive MCP tool that reads file metadata.
Route the MCP server's outbound Drive calls through this Resource Gateway under
an assigned identity. Then check both synthetic file IDs through the tool and
through direct HTTPS from the test device. Verify that both interfaces can read
the allowed file and that Forge blocks both reads of the restricted file.

In **Live → Resources**, check all four operations. Confirm the caller identity
on each path and the policy name on both blocked reads. Send a request from the
same device to an unrelated approved destination. Confirm that it still succeeds.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.