# Call salesforce api from react without exposing access token

> Vault-inject OAuth or integration tokens at the edge; React calls one public client token URL. For "call salesforce api from react without exposing access token", store SALESFORCE_ACCESS_TOKEN in Secret Vault, call https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}} from a Worker, and let React hit only https://realcomposer.com/v1/workspace/call-salesforce-api-from-react-securely with an rc_live_ client token.

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

## Problem: Why React leaks Salesforce credentials

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

- Production Salesforce 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**: Store SALESFORCE_ACCESS_TOKEN in the vault. React never embeds the raw secret, only a revocable rc_live_ client token.

2. **Configure upstream steps and output mapping**: Configure headersTemplate to inject vault secrets, target https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from React**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/call-salesforce-api-from-react-securely', {
  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": "Call salesforce api from react without exposing access token",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "salesforce",
      "upstreamUrlTemplate": "https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.SALESFORCE_ACCESS_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "contactId",
        "sourcePath": "Id",
        "type": "string",
        "sourceStep": "salesforce"
      },
      {
        "targetPath": "email",
        "sourcePath": "Email",
        "type": "string",
        "sourceStep": "salesforce"
      },
      {
        "targetPath": "name",
        "sourcePath": "Name",
        "type": "string",
        "sourceStep": "salesforce"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/call-salesforce-api-from-react-securely" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_call-sal",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "call-salesforce-api-from-react-securely"
  },
  "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",
  "name": "sample"
}
```

## FAQ

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

Point React at /recipes/call-salesforce-api-from-react-securely edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

Cache key for call-salesforce-api-from-react-securely: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### How do I rotate upstream credentials?

Upstream steps in call-salesforce-api-from-react-securely honor timeoutMs and optional fallback JSON without leaking secrets.
