# Hide salesforce api credentials in javascript client app

> Edge pipeline attaches Bearer tokens so static sites never embed secrets. For "hide salesforce api credentials in javascript client app", 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 JavaScript / HTML hit only https://realcomposer.com/v1/workspace/hide-salesforce-credentials-javascript with an rc_live_ client token.

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

## Problem: Why JavaScript / HTML leaks Salesforce credentials

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

- Production Salesforce keys copied from JavaScript / HTML bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop

## Solution steps

1. **Store upstream credentials in Secret Vault**: Create SALESFORCE_ACCESS_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Configure upstream steps and output mapping**: Use GET against https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}. 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 JavaScript / HTML**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const data = await fetch('https://realcomposer.com/v1/workspace/hide-salesforce-credentials-javascript', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
}).then(r => r.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 salesforce api credentials in javascript client app",
  "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/hide-salesforce-credentials-javascript" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_hide-sal",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "hide-salesforce-credentials-javascript"
  },
  "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

### What should JavaScript / HTML store instead of Salesforce secrets?

Yes for hide-salesforce-credentials-javascript. Ship only an rc_live_ client token in JavaScript / HTML; RealComposer injects SALESFORCE_ACCESS_TOKEN on https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}.

### Will Anthropic or Linear prompt bodies be rewritten?

hide-salesforce-credentials-javascript forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

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

Upstream steps in hide-salesforce-credentials-javascript honor timeoutMs and optional fallback JSON without leaking secrets.
