# Call Github API with Private Personal Access Token from Client

> Frontend / Web cannot safely store GitHub production keys. Vault-bound headers reach https://api.github.com/user/repos?per_page=5 on Workers while apps call your github-api-private-token-proxy edge URL.

- Canonical page: https://realcomposer.com/recipes/github-api-private-token-proxy
- Client platform: Frontend / Web
- Upstream services: GitHub
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/github-api-private-token-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=github-api-private-token-proxy&via=agent

## Problem: Why Frontend / Web leaks GitHub credentials

Attackers routinely extract GitHub secrets from Frontend / Web builds. Direct browser calls also expose internal error payloads with hostnames.

- Production GitHub keys copied from Frontend / Web bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop

## Solution steps

1. **Add vault secrets for this pipeline**: Store GITHUB_TOKEN in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.

2. **Target the real upstream URL**: Configure headersTemplate to inject vault secrets, target https://api.github.com/user/repos?per_page=5, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from Frontend / Web**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/github-api-private-token-proxy', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Call Github API with Private Personal Access Token from Client",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "github",
      "upstreamUrlTemplate": "https://api.github.com/user/repos?per_page=5",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.GITHUB_TOKEN}}",
        "Accept": "application/vnd.github+json"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "repoId",
        "sourcePath": "0.id",
        "type": "number",
        "sourceStep": "github"
      },
      {
        "targetPath": "fullName",
        "sourcePath": "0.full_name",
        "type": "string",
        "sourceStep": "github"
      },
      {
        "targetPath": "isPrivate",
        "sourcePath": "0.private",
        "type": "boolean",
        "sourceStep": "github"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/github-api-private-token-proxy" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_github-a",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "github-api-private-token-proxy"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "repoId": "sample",
  "fullName": "sample",
  "isPrivate": "sample"
}
```

## FAQ

### Can Frontend / Web call GitHub without holding the production key?

Use scoped tokens where the vendor allows them on github-api-private-token-proxy. Admin keys stay {{secrets.*}} references only.

### How do I forward JSON bodies to POST upstreams?

github-api-private-token-proxy keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### How do I rotate upstream credentials?

Rotate vault secrets for github-api-private-token-proxy anytime; clients keep the same rc_live_ token.
