# Hide intercom access token in react app

> Intercom contacts and events via edge proxy with server-side Bearer token. For "hide intercom access token in react app", store INTERCOM_ACCESS_TOKEN in Secret Vault, call https://api.intercom.io/contacts from a Worker, and let React hit only https://realcomposer.com/v1/workspace/hide-intercom-access-token-react with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/hide-intercom-access-token-react
- Client platform: React
- Upstream services: Intercom
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/hide-intercom-access-token-react.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=hide-intercom-access-token-react&via=agent

## Problem: Why React leaks Intercom credentials

Attackers routinely extract Intercom secrets from React builds. Direct browser calls also expose internal error payloads with hostnames.

- Production Intercom keys copied from React bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add INTERCOM_ACCESS_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Target the real upstream URL**: Use GET against https://api.intercom.io/contacts. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache).

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

```
const res = await fetch('https://realcomposer.com/v1/workspace/hide-intercom-access-token-react', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
const data = await res.json();
```

## 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": "Hide intercom access token in react app",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "intercom",
      "upstreamUrlTemplate": "https://api.intercom.io/contacts",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.INTERCOM_ACCESS_TOKEN}}",
        "Accept": "application/json"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "contactId",
        "sourcePath": "data.0.id",
        "type": "string",
        "sourceStep": "intercom"
      },
      {
        "targetPath": "email",
        "sourcePath": "data.0.email",
        "type": "string",
        "sourceStep": "intercom"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/hide-intercom-access-token-react" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_hide-int",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "hide-intercom-access-token-react"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "contactId": "sample",
  "email": "sample"
}
```

## FAQ

### Which Intercom credential belongs in the vault for this pipeline?

Log request IDs for hide-intercom-access-token-react, not raw Intercom payloads, because upstream bodies may include PII.

### What cache key does RealComposer use?

hide-intercom-access-token-react vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### Can I restrict which domains call this pipeline?

Upstream steps in hide-intercom-access-token-react honor timeoutMs and optional fallback JSON without leaking secrets.
