---
title: "Provider accounts"
description: "Provider accounts from the built-in skills in Executor 2.0.0-beta.79."
---

This page covers Use a provider account from the [built-in skills](/docs/reference/skills) shipped with Executor `2.0.0-beta.79`. It contains `app-authoring/accounts.md`.

Next: [Provider accounts · Check an account](/docs/reference/skills/app-authoring/accounts-2)

## Use a provider account

Declare the provider's credential shape in source. The host derives its provider
ID, stores account credentials and supplies the accounts each call runs with.
Never put real tokens into source files or return them from tools.

Each requirement is one of two scopes:

- `user`: each caller's own account. Every member links their own, and
  `ctx.user.accounts.<name>` is the caller's.
- `app`: the app's own account, such as a team's service key. People who can
  edit the app link it for everyone, and `ctx.app.accounts.<name>` is that
  account for every caller and for the app's background work. Callers never
  choose or replace it.

Use `user` unless the account belongs to the team rather than to whoever calls
the tool. A requirement name is used once across both scopes.

**The provider ID comes from the whole definition except `hosts` and setup
help, including `name`, labels and OAuth `scopes`.** Changing any of them after
users connect gives a new provider, and existing accounts no longer fit the
slot. Users must connect a new account. Settle these before users connect.
Setup help ([below](/docs/reference/skills/app-authoring/accounts-2#tell-users-where-to-get-credentials)) can change at any
time.

This is a complete `index.ts` for Vercel with an API token:

```ts
import {
  query,
  type QueryContext,
  array,
  decodeJson,
  defineApp,
  defineProvider,
  object,
  secrets,
  string,
  router,
} from "apps";

const vercel = defineProvider({
  name: "Vercel",
  auth: {
    apiKey: secrets({
      label: "API token",
      fields: object({ token: string({ minLength: 1 }) }),
    }),
  },
});

const requirements = { user: { accounts: { vercel } } };
type Context = QueryContext<typeof requirements>;
const Projects = object({ projects: array(object({ id: string(), name: string() })) });
const listProjects = query(
  { description: "List projects accessible to the caller's Vercel account", input: object({}) },
  async (ctx: Context) => {
    const response = await ctx.fetch("https://api.vercel.com/v9/projects?limit=10", {
      headers: { Authorization: `Bearer ${ctx.user.accounts.vercel.fields.token}` },
    });
    return decodeJson(response, Projects);
  },
);

export default defineApp(requirements, { tools: router({ listProjects }) });
```

For one account every caller uses instead, declare it under `app` and read
`ctx.app.accounts.vercel`:

```ts
const requirements = { app: { accounts: { vercel } } };
```

A context of the `"app"` scope, such as `QueryContext<typeof requirements, "app">`,
has no `user`. App schedules, webhooks whose source is an app account and the
workflows they start run without a caller and use it; see
[workflows.md](/docs/reference/skills/app-authoring/background-work#workflows) and [webhooks.md](/docs/reference/skills/app-authoring/background-work#webhook-subscriptions).

## Limit where credentials go

Declare `hosts` so app code never holds the secret values. Each unmarked string
field then reaches the app as an opaque handle. Executor's network replaces a
handle with the real value only on requests to a declared host, in the URL,
headers, Basic credentials, and JSON, form or text bodies up to 1 MiB. A token
the service takes in the URL path works the same way:
``ctx.fetch(`https://api.telegram.org/bot${account.fields.token}/getMe`)``.
For a generated router, pass a `fetch` that rewrites the URL. Executor
refuses a request that sends a handle anywhere else: `ctx.fetch` rejects with
`NetworkRefused`, naming the host and the provider's allowed hosts, and the
global `fetch` receives status 421 with the same details. A request that carries
a handle is never sent with `TRACE`. Values the service echoes back in headers or
in JSON, form or text bodies up to 1 MiB reach the app as handles; other
responses reach it as the service sent them, so the declared hosts are trusted
not to echo a credential back.

**Adding a host to a provider that already declares hosts means users must
connect existing accounts again.** Each account keeps the hosts it was connected
with, so Executor refuses requests that send its credentials to the new host
until it is reconnected. Declare every host the app needs before users connect
accounts.

```ts
import { defineProvider, object, plain, raw, secrets, string } from "apps";

const example = defineProvider({
  name: "Example",
  hosts: ["api.example.com", "*.example.com"],
  auth: {
    apiKey: secrets({
      label: "API key",
      fields: object({
        region: plain(string()), // not secret; the app reads it and the form shows it
        token: string(), // secret: the app reads a handle
        signingKey: raw(string()), // secret the app must read, such as a signing key
      }),
    }),
  },
});
```

A host is an exact name, `host:port`, or `*.` plus a domain for one level of
subdomain. Pass handles to headers and clients as ordinary strings. Do not
decode, hash or sign them; mark such a field `raw()`, and the connect form
warns that the app can read it. Multipart and streamed bodies are sent
unchanged. A provider without `hosts` gives app code real values unless the
account was connected with hosts. Changing `plain()` or `raw()` changes the
provider, so existing accounts must be connected again.

Basic credentials work with handles. Encode `username:password` with `btoa` as
usual; Executor decodes a `Basic` `Authorization` header, replaces the handles
inside it and encodes it again. With a `request` (see below), declare
`basic(username, password)` and send `account.headers()` instead. This [check](/docs/reference/skills/app-authoring/accounts-2#check-an-account) sends a
`secrets` method's `username` and `password` fields to a declared host:

```ts
async health({ account, fetch, signal }) {
  const basic = btoa(`${account.fields.username}:${account.fields.password}`);
  const response = await fetch("https://api.example.com/v1/me", {
    signal,
    headers: { Authorization: `Basic ${basic}` },
  });
  const me = await decodeJson(response, object({ id: string(), email: string() }));
  return { accountInfo: { externalId: me.id, email: me.email } };
},
```

## Place credentials exactly

`hosts` limits where a credential goes; `request` also limits where in the
request it goes. Give a method a `request` and Executor substitutes its handles
only as the whole value of the declared headers or query parameters, matching
the template exactly. A handle anywhere else (a body, the URL path, another
header, or a value with extra text) is refused with `NetworkRefused`
(`credential_placement`), so a service cannot be made to store the secret and
hand it back. A provider that declares `request` must declare `hosts`. Placed
credentials go only over HTTPS; plain HTTP is refused (`credential_transport`),
except to a loopback address on an instance that lets apps reach private
addresses, for local development.

`request` receives a reference for each of the method's fields and runs once,
when the provider is declared. Build values with the tagged template `t`; an
untagged template literal throws. `header(name, value)` and `query(name, value)`
choose the location; `base64(value)` encodes; `bearer(token)` and
`basic(user, password)` are shorthands for the usual `Authorization` values:

```ts
import {
  base64,
  bearer,
  defineProvider,
  header,
  oauth2,
  object,
  plain,
  query,
  secrets,
  string,
  t,
} from "apps";

const jira = defineProvider({
  name: "Jira",
  hosts: ["*.atlassian.net"],
  auth: {
    token: secrets({
      label: "API token",
      fields: object({ email: plain(string()), token: string() }),
      request: ({ email, token }) =>
        header("authorization", t`Basic ${base64(t`${email}:${token}`)}`),
    }),
    oauth: oauth2({
      discover: "https://auth.atlassian.com",
      scopes: ["read:jira-work"],
      request: ({ access_token }) => bearer(access_token),
    }),
  },
});

const google = defineProvider({
  name: "Google API key",
  hosts: ["www.googleapis.com"],
  auth: {
    key: secrets({
      label: "API key",
      fields: object({ key: string() }),
      request: ({ key }) => [header("x-goog-api-key", key), query("key", key)],
    }),
  },
});
```

Each placement references at least one secret field, never a `raw()` field.
`plain()` fields in a template are copied as the app sends them. Send the
credentials with the account's `headers()` and `url()`, which render the
declared placements with the handles app code holds:

```ts
const response = await fetch(account.url("https://www.googleapis.com/books/v1/volumes?q=x"), {
  headers: { ...account.headers(), accept: "application/json" },
});
```

A header written by hand also works when it matches the template exactly.
`request` is part of the provider's identity, like `plain()` and `raw()`:
adding or changing it means existing accounts must be connected again.
Bodies over 1 MiB and streamed bodies are not searched; a handle in one is sent
as the handle, never the value.

Some accounts are connected through an OAuth client the Executor instance
provides. Their credentials are always handles, `plain()` and `raw()` do not
apply, and `request` is replaced by the instance's own header: send
`account.headers()`. The token goes only to the instance's hosts that the
provider also declares, so a provider without `hosts` sends it nowhere. A handle
of such an account anywhere but that header is refused.
