<!-- llms.txt: https://workos.com/llms.txt -->
<!-- feedback.md: https://workos.com/docs/feedback.md -->

# Pipes

## Introduction

Pipes allows your users to securely connect their third-party accounts to your
application. With Pipes, you can easily integrate with popular services like
GitHub, Slack, Google, Salesforce, and many more without managing OAuth flows,
token refresh logic, or credential storage.

By default each user connects and owns their own account. To let an
organization administrator connect a provider once and share it with every
member, see [connection sharing](https://workos.com/docs/pipes/connection-sharing).

## Configuring providers

To make an provider available to your users, you will need to configure it in
the WorkOS Dashboard.

Visit the *Pipes* section of the WorkOS Dashboard to get started. Click *Connect
provider* then choose the provider from the list. If you don't see the provider
you need, you can [define a custom provider](https://workos.com/docs/pipes/custom-providers) or reach
out to [our team](mailto:support@workos.com).

### Custom Credentials

Configure the provider with your own OAuth credentials:

1. **Create an OAuth application** within the provider's dashboard.
   1. You can find instructions on setting up the provider in the documentation section of the setup modal.
2. Use the provided **redirect URI** when configuring the provider.
3. Set the **client ID and secret** from the provider.
4. Specify the required **scopes** for your application.
   1. You may need to set these scopes in the provider configuration as well.
5. Provide an optional **description**. This will be used in the widget to inform users
   on how your application will use their data from the provider.

Commonly used scopes are provided in-line, but you should consult each provider's documentation for the full list of available scopes.

### Client credentials

Some providers let your application call their API server-to-server, with no
user signing in. For those providers, choose *Client credentials* as the
authentication method when you add them, then set the default scopes requested
on each organization's behalf and an optional description. You can also declare
the provider from your backend with the
[create data integration](https://workos.com/docs/reference/pipes/data-integration/create) endpoint by
setting `auth_methods` to `["client_credentials"]`.

Each organization supplies its own client ID and client secret when it connects
through the
[Pipes widget](https://workos.com/docs/widgets/pipes), along with any provider configuration the
connect form collects—for Salesforce, the organization's My Domain host.

![The Pipes widget "Connect Salesforce with client credentials" dialog, with fields for the client ID, the client secret, and the Salesforce My Domain host.](https://images.workoscdn.com/images/0679a838-b23b-42df-9935-7ace14a73dd3.png?auto=format\&fit=clip\&q=80)

## Provider management in your application

The [Pipes Widget](https://workos.com/docs/widgets/pipes) provides a pre-built UI for users to connect
and manage their connected accounts. The widget shows the user which
providers are available, and lets them easily initiate the authorization
flow. It communicates with the WorkOS API and stores the connection information
for the user. If there's ever a problem with the user's access token, the widget
will let them know they need to reauthorize.

![Pipes widget screenshot](https://images.workoscdn.com/images/e84a33bb-0510-4d85-9041-33b1a0ce938c.png?auto=format\&fit=clip\&q=50)

> The description in the widget is set in the provider's configuration in the WorkOS Dashboard.

### Building your own authorization flow

If you'd rather not use the widget, you can start the authorization flow from
your own UI with the API. Your server
[requests an authorization URL](https://workos.com/docs/reference/pipes/connected-account/get-authorize-url)
for the user and redirects them to it, and the user is sent back to your
application after they authorize the provider.

Before you build a custom flow, read
[Securing the authorization flow](https://workos.com/docs/pipes/securing-authorizations). It explains
how to make sure the provider account gets connected to the user who started
the authorization, and not to someone else who opened the same URL.

## Fetching access tokens

Once a user has connected a provider, you can [fetch access tokens](https://workos.com/docs/reference/pipes) from your
backend to make API calls to the connected service on their behalf. Pipes takes
care of refreshing the token if needed, so you'll always have a fresh token. If
there's a problem with the token, the endpoint will return information about the issue so you can
direct the user to the correct it. This may require sending the user to re-authorize directly
or via the page with the Pipes widget.

:::code-group

```js language="js"
import { Octokit } from '@octokit/rest';
import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS(process.env.WORKOS_API_KEY);

async function getUserGitHubRepos(userId, organizationId) {
  const { accessToken, error } = await workos.pipes.getAccessToken({
    provider: 'github',
    userId: userId,
    organizationId: organizationId,
  });

  if (!accessToken) {
    // Handle error: user needs to connect or reauthorize
    console.error('Token not available:', error);
    return;
  }

  // Check if required scopes are missing
  if (accessToken.missingScopes.includes('repo')) {
    console.error('Missing required "repo" scope');
    return;
  }

  // Use the access token with GitHub API
  const octokit = new Octokit({
    auth: accessToken.token,
  });

  const { data: repos } = await octokit.repos.listForAuthenticatedUser();

  return repos;
}
```

:::

This fetches the user's own connection. To fetch an organization's shared
connection instead, pass `connection_owner: "organization"` as described in
[connection sharing](https://workos.com/docs/pipes/connection-sharing#fetching-credentials).

## Calling provider APIs

Pipes offers two ways to make provider API calls on a user's behalf, both built
on the same connections and token refresh machinery. They differ in where the
user's token ends up.

- **Access tokens.** The
  [vend credentials](https://workos.com/docs/reference/pipes/access-token/vend-credentials) endpoint
  returns the user's access token so your code can call the provider directly.
- **[Relay](https://workos.com/docs/pipes/relay).** WorkOS calls the provider for you and
  returns its response, so the token never enters your environment.

Every active response from the vend credentials endpoint includes
`credential.config`, whether the credential uses OAuth, an API key, or client
credentials. This object contains provider-declared, non-secret configuration
from the connected account's stored snapshot, with current provider defaults
for unset fields. Use it to identify a tenant-specific host, such as a Snowflake
account or Zendesk subdomain. Fields removed from the provider definition and
fields marked secret are omitted; the object is empty when no values are
available to disclose.

Editing integration or organization configuration does not update an existing
connection's snapshot. Reconnect or explicitly rebind the connection to adopt
those edits. Defaults remain live: a changed default can appear in `config`
before a cached token is refreshed or re-minted. For credentials that never
refresh, a routing-default change requires reconnecting or rebinding the
connection.

|                           | Access tokens                                 | Relay                                     |
| ------------------------- | --------------------------------------------- | ----------------------------------------- |
| You receive               | The provider access token                     | The provider's API response               |
| Who calls the provider    | Your code                                     | WorkOS                                    |
| Token in your environment | Yes                                           | Never                                     |
| User identified by        | `user_id` in the JSON body                    | `X-Relay-User` header                     |
| Missing connection        | `200` with `{"active": false}`                | `402` with an `authorization_url`         |
| Best for                  | Trusted infrastructure and long-running syncs | Agents, sandboxes, and untrusted runtimes |

Use the relay when the code making provider calls runs somewhere a live
OAuth token shouldn't live, such as an agent sandbox, ephemeral compute, or a
customer-controlled environment.
