> ## 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.

# GitHub API

> Route read-only GitHub REST API requests through a Resource Gateway and block one repository operation.

Use a private test repository to verify that Forge brokers a GitHub credential
and blocks a specific REST API operation. Both requests in this recipe are
read-only.

## Set up the Resource

1. Use an online [Resource Gateway](https://docs.forge.ai/resources/deploy-resource-gateway.md) with
   outbound HTTPS access to `api.github.com`.
2. Create a short-lived [fine-grained GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token)
   for the private test repository. Select only that repository and use
   **Metadata** read access. GitHub requires this permission for
   [Get a repository](https://docs.github.com/en/rest/repos/repos#get-a-repository)
   and [Get all repository topics](https://docs.github.com/en/rest/repos/repos#get-all-repository-topics).
3. In **Policies → Resources**, select **New resource**. Name it
   `GitHub API qualification`. Select **HTTP**, enter `api.github.com` on port
   `443`, and turn on **Use HTTPS**. Assign the gateway and save.
4. On the Resource page, add a **Bearer token** credential with the GitHub
   token. Assign it to the test user. Forge adds the GitHub token to permitted
   upstream requests. See [Credentials and identity](https://docs.forge.ai/resources/credentials-and-identity.md).
5. Open **Connect directly**. Download the trust certificate and select
   **Generate access**. Use the generated Forge access credential in the
   direct client.

## Establish a direct-access baseline

Replace `resources.example.com`, `OWNER`, and `REPO` with your gateway
hostname and test repository. Run the setup in Bash or Zsh. When `read` waits
for input, paste the short-lived Forge access token and press Enter.

```bash theme={"system"}
GATEWAY_URL='https://resources.example.com'
REPO_PATH='/repos/OWNER/REPO'
read -rs FORGE_ACCESS_TOKEN

github_via_forge() {
	printf 'Proxy-Authorization: Bearer %s\n' "$FORGE_ACCESS_TOKEN" |
		curl --silent --show-error --cacert forge-resource-ca.pem \
			--header @- \
			--header 'Accept: application/vnd.github+json' \
			--header 'X-GitHub-API-Version: 2026-03-10' \
			--write-out '\nHTTP %{http_code}\n' \
			"${GATEWAY_URL}$1"
}

github_via_forge "$REPO_PATH"
github_via_forge "$REPO_PATH/topics"
```

Confirm that both calls return HTTP `200`. Check the private repository name
in the first response. The second response contains a `names` array, which can
be empty.

## Block the topics endpoint

Create a **Resource policy** named `Block GitHub test repository topics` and
scope it to `GitHub API qualification`. Set **Condition type** to **Match all**
and add the following conditions.

* **HTTP method** **Equals** `GET`.
* **HTTP path** **Equals** `/repos/OWNER/REPO/topics`. Substitute the same
  owner and repository you used in the baseline.

Select **Block** and **Enforce**. Set the user message to
`GitHub test repository topics are blocked by Forge.` Enable and save the
policy. See [Resource Policies](https://docs.forge.ai/secure/resource-policies.md).

Generate a fresh Forge access token and repeat both requests. The repository
request returns HTTP `200`. The topics
request returns HTTP `403` with the Forge message and policy ID. In
**Live → Resources**, confirm an allowed repository request and a topics
request blocked by the named policy. Verify that both events identify the test
user.

Clear the temporary client credential when you finish.

```bash theme={"system"}
unset FORGE_ACCESS_TOKEN
```

## Repeat with automatic routing

Select only the enrolled test devices for this run. Once a test device
reports **Active** routing and trusts the organization inspection CA, enable
**Automatic routing** on the Resource. Wait for the device to receive the
updated configuration. Use fresh connections to the original hostname. See
[Automatic routing](https://docs.forge.ai/resources/automatic-routing.md).

On the test device, replace `OWNER` and `REPO` with the same values you used
for direct access.

```bash theme={"system"}
REPO_PATH='/repos/OWNER/REPO'

github_from_device() {
	curl --silent --show-error \
		--header 'Accept: application/vnd.github+json' \
		--header 'X-GitHub-API-Version: 2026-03-10' \
		--write-out '\nHTTP %{http_code}\n' \
		"https://api.github.com$1"
}

github_from_device "$REPO_PATH"
github_from_device "$REPO_PATH/topics"
```

Verify the same HTTP `200` and Forge `403` outcomes. Check the user and device
in **Live → Resources**. Automatic routing uses the enrolled device identity,
and the gateway supplies the assigned GitHub credential.

To check upstream receipt independently, repeat the policy test with a
separate HTTPS Resource pointing at a private test server that logs both
paths. After the policy is active, the server log should contain the allowed
request and no entry for the blocked request. The GitHub test above verifies
provider authentication and the Forge decision. The private server test
verifies forwarding behavior with origin logs.


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