# Call Plaid API from Flutter without Exposing Client Secret

> Frontend / Web cannot safely store Plaid production keys. Vault-bound headers reach https://production.plaid.com/accounts/get on Workers while apps call your plaid-api-proxy-flutter edge URL.

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

## Problem: Why Frontend / Web leaks Plaid credentials

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

- Production Plaid 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**: Add PLAID_SECRET to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: Use POST against https://production.plaid.com/accounts/get. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge. Plaid /accounts/get expects client_id and secret inside the JSON body your app POSTs. Header injection alone cannot authenticate Plaid.

3. **Call from Frontend / Web**: Call https://realcomposer.com/v1/workspace/plaid-api-proxy-flutter with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.

```
const res = await fetch('https://realcomposer.com/v1/workspace/plaid-api-proxy-flutter', {
  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 Plaid API from Flutter without Exposing Client Secret",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "plaid",
      "upstreamUrlTemplate": "https://production.plaid.com/accounts/get",
      "httpMethod": "POST",
      "headersTemplate": {
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "accountId",
        "sourcePath": "accounts.0.account_id",
        "type": "string",
        "sourceStep": "plaid"
      },
      {
        "targetPath": "name",
        "sourcePath": "accounts.0.name",
        "type": "string",
        "sourceStep": "plaid"
      },
      {
        "targetPath": "type",
        "sourcePath": "accounts.0.type",
        "type": "string",
        "sourceStep": "plaid"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/plaid-api-proxy-flutter" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_plaid-ap",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "plaid-api-proxy-flutter"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "accountId": "sample",
  "name": "sample",
  "type": "sample"
}
```

## FAQ

### What should Frontend / Web store instead of Plaid secrets?

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

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

Cache key for plaid-api-proxy-flutter: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### What happens if an upstream step times out?

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