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

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

Previous: [Provider accounts · Check an account](/docs/reference/skills/app-authoring/accounts-2) · Next: [Provider accounts · OAuth sign-in (continued)](/docs/reference/skills/app-authoring/accounts-4)

## OAuth sign-in

Prefer discovery. When the service publishes OAuth authorization server or OpenID
metadata, point `discover` at its issuer or MCP URL. Executor then reads the real
issuer, endpoints and supported client authentication, and checks the service's
responses against them:

```ts
const searchConsole = defineProvider({
  name: "Google Search Console",
  auth: {
    oauth: oauth2({
      discover: "https://accounts.google.com",
      scopes: ["https://www.googleapis.com/auth/webmasters"],
      // Google issues refresh tokens only when asked for offline access.
      authorizationParams: { access_type: "offline", prompt: "consent" },
    }),
  },
});
```

Check for metadata at `<issuer>/.well-known/oauth-authorization-server` or
`<issuer>/.well-known/openid-configuration`. The issuer is often the host of the
sign-in page, not the token URL: Google signs in at `accounts.google.com` and
issues tokens from `oauth2.googleapis.com`. List the scopes the app needs;
discovery only fills them in when the service advertises scopes for the resource.

When the service publishes its metadata at a nonstandard location, keep `discover`
pointing at the MCP resource or issuer and declare the exact document URL:

```ts
oauth2({
  discover: "https://mcp.example.com",
  authorizationServerMetadataUrl: "https://auth.example.com/oauth/.well-known/openid-configuration",
  scopes: ["reports:read", "offline_access"],
});
```

The host still checks the document's `issuer` against the issuer discovered from
`discover`. It applies its network policy and never follows a redirect or falls
back to another document when the explicit URL fails. The endpoints come from the
validated metadata; the issuer check cannot be disabled.

For MCP discovery, explicit `scopes` take precedence over the resource's Bearer
challenge scope, which takes precedence over its protected-resource metadata
`scopes_supported`. Authorization-server supported scopes are not requested
wholesale. Keep `openid`, `profile` and `email` only when the service or app needs
identity; an access-token-only app can declare its resource scopes explicitly.
The host adds `offline_access` when advertised and `scopes` is omitted.

Sign-in sends one RFC 8707 resource indicator on authorization, exchange and
renewal: `resource` when declared, otherwise the one the protected-resource
metadata names. `accounts.oauthSetup` reports it as `resource: { value, source }`;
`value` is null when it sends none, and `source` says why. When the service
refuses it (`resource_rejected`) or refuses the token it issued, declare the
identifier the service documents, or `resource: null` to send none. Declaring the
value discovery already found changes nothing. With `source: "operator"` the
instance's own OAuth client sets it, and only the instance administrator can
change it; the provider's `resource` does not apply. With
`source: "inferred_scope_audience"` Executor sent none because the authorization
server's metadata looks like Microsoft identity platform v2.0's, which takes the
audience from the scopes. That is Executor's guess from the service's metadata;
if the service refuses the sign-in, declare `resource`.

Standard discovery requires the metadata's `issuer` to equal the issuer used to
construct the well-known metadata URL.
Microsoft Entra ID's multi-tenant `common` and `organizations` endpoints publish
the template `https://login.microsoftonline.com/{tenantid}/v2.0` instead, which
discovery accepts. Its `consumers` endpoint names a different issuer in its
metadata and fails the check: declare its endpoints and issuer.

`authorizationParams` adds service-defined parameters to the sign-in request,
from the service's docs. Use it for settings such as offline access or a
service's own selector, for example `{ providers: "..." }`. It works with
`discover` and with declared endpoints. Executor sets the protocol parameters
itself, so these names are rejected: `response_type`, `client_id`,
`redirect_uri`, `state`, `scope`, `code_challenge`, `code_challenge_method`,
`nonce`, `resource`, `request` and `request_uri`. Use `scopes` and `resource`
for those settings instead.

Declare `authorizationUrl`, `tokenUrl` and `scopes` only when the service
publishes no metadata. Then set `tokenEndpointAuthMethod` to what its docs say
the token endpoint accepts (`client_secret_basic`, `client_secret_post`, or `none`
for public PKCE clients), and `issuer` when the docs name one, so Executor can
check the service's `iss` responses. Without `issuer` those checks are skipped.
Do not copy endpoints from an OpenAPI `oauth2` scheme without checking the
service's docs; those schemes carry no issuer or client authentication.

A declared `authorizationUrl` may include a query string, such as
`https://auth.example.com/authorize?tenant=acme`; Executor keeps it and adds the
protocol parameters. Prefer `authorizationParams` for service settings. Declare
each parameter in one place: a name in both the URL and `authorizationParams`,
or a protocol parameter in the URL, fails the build.

Some services read OAuth requests or answer them differently from the
standard. Declare the difference from the service's docs; do not work around it
in app code:

- `scopeSeparator: ","` joins `scopes` with commas on the sign-in request, as
  Linear requires. The default is a space.
- `tokenRequestFormat: "json"` sends token requests (sign-in, renewal and
  client credentials) as a JSON object, as Atlassian, ClickUp and Notion
  require. The default is a form.
- `tokenResponse: { path: "authed_user" }` reads the grant from a nested member
  of the token response when the top level has no access token or scope.
  Slack returns user tokens there. Comma-separated scopes in that member become
  space-separated.
- `pkce: false` signs in without PKCE, for declared endpoints whose token
  endpoint refuses a confidential client's `code_verifier`. LinkedIn answers
  `invalid_client` to it, which looks like a wrong secret. It requires a secret
  `tokenEndpointAuthMethod`.

```ts
oauth2({
  authorizationUrl: "https://slack.com/oauth/v2/authorize",
  tokenUrl: "https://slack.com/api/oauth.v2.access",
  scopes: [],
  // Slack names user scopes in its own parameter.
  authorizationParams: { user_scope: "search:read,channels:history" },
  tokenResponse: { path: "authed_user" },
});
```

A connected account keeps the settings it signed in with. These settings,
`pkce` included, are part of the provider ID, so changing one after users
connect gives a new provider: accounts connected before can't be reconnected
into it, and users must connect a new account. A sign-in in progress when the
app is redeployed fails when it saves, and the user starts it again.

When the service documents an RFC 7009 token revocation endpoint, also declare
`revocationUrl`. Executor calls it when a user deletes the account, so the
provider stops honoring the saved token. Revocation is best effort and never
blocks the deletion. Discovered methods use the server's advertised
`revocation_endpoint` and do not accept `revocationUrl`.

Executor renews tokens before they expire. An `expires_in` of zero is treated
like an omitted one: the token is used until the service rejects it. A tool call
fails with `OAuthReconnectRequired` only when the token endpoint refuses the
renewal, such as with `invalid_grant`, or a renewed ID token names a different
user; reconnect that same account. During a
service outage, or when its response cannot be used, the call fails with the
retryable `OAuthRenewalFailed` and the saved sign-in is kept, so retry later
instead of reconnecting or changing the provider.

For service-to-service access without a user's sign-in, declare the client
credentials grant with `tokenUrl` (or `discover`), `scopes`, and the client
authentication the token endpoint accepts: `client_secret_basic`,
`client_secret_post`, or `client_secret_basic_raw` for a service that wants the
Basic credentials without form encoding.

```ts
const reports = defineProvider({
  name: "Reports",
  auth: {
    machine: oauth2({
      grant: "client_credentials",
      tokenUrl: "https://auth.example.com/oauth/token",
      scopes: ["reports:read"],
      tokenEndpointAuthMethod: "client_secret_basic",
    }),
  },
});
```

The connect page asks for the client ID and secret and exchanges them at once;
there is no browser redirect. App code reads `account.fields.access_token`.
Executor exchanges the client credentials again when the token expires; this
grant has no refresh token.

Deploy the source, then request a connection for its account requirement.
Use `appAccounts.userConnect` for a user requirement and
`appAccounts.appConnect` for one of the app's own requirements. The examples
below use the **local** API; hosted calls add `organization` to `path`, as shown
in [deploy.md](/docs/reference/skills/app-authoring/deploy#local-source-with-the-cli).
Hosted calls derive owner and subject from the caller. Local assigns owners
itself: apps you create belong to `local`, whatever owner you send, and a
connected account belongs to its app's owner, so a connection request takes no
owner. Read the operation signatures with `tools.search` before calling them:

```js
const executor = tools.executor;
const app = await executor.apps.get({ path: { app: "<vercel-app-id>" } });
return await executor.appAccounts.userConnect({
  path: { app: app.id, requirement: "vercel" },
  body: {},
});
```

Give the returned URL to the user. Executor renders the provider's credential
form or OAuth sign-in. Never ask users to paste secrets into chat, inspect their
files for tokens, or put credentials in app source or execute code.
After the user finishes, check the request in a new execute call:

```js
const connection = await tools.executor.accountConnections.get({
  path: { connection: "<connection-id>" },
});
return connection.state; // { status: "completed", account } means setup finished.
// A pending state with `failure` holds the error the user saw, including the service's own error.
```

Cloud and self-host have no `accountConnections`; read the request with
`accounts.connection`, passing `path: { organization, connection }`. Its
result also has `url` and `redirectUri`. On every host the connect tools
require `body`; send `body: {}` when there is nothing to put in it.

Completing a request saves the account and links it to the requirement in one
transaction: for the caller for a user requirement, for everyone for an app
requirement. Only people who can edit the app can request one for an app
requirement; completion is refused with `AccountConnectionRefused` when the
person may no longer link it. If the requirement changed during sign-in, completion returns
`AccountConnectionTargetChanged` without saving credentials; request a new link.
A pending link whose app was redeployed with a different provider for that
requirement, such as an API key instead of OAuth, returns the same error when read
or opened. Request a new link after such a deploy.

Every request names an app requirement; there are no standalone connections. To
replace the credentials of an account the app already uses, pass its ID as
`account` in the body. The account keeps its ID, name and links:

```js
return await tools.executor.appAccounts.userConnect({
  path: { app: "<app-id>", requirement: "vercel" },
  body: { account: "<account-id>" },
});
```

Requests expire after thirty minutes. Cancelled or expired requests need a new link. Do not wait or busy-poll
inside execute.

Use `accounts.list({ query: { owner: "local", provider } })` to find compatible
saved accounts first when appropriate. `owner` is required; listing never spans
owners.

Each scope has the same tools, `appAccounts.user.*` for the caller's own links
and `appAccounts.app.*` for the app's, each taking
`path: { app, requirement[, account] }`, plus `organization` on hosted:
