Skip to content

OAuth Connections

OAuth connections are the primary way to get credentials for third-party APIs. Authpipe handles the full OAuth 2.0 flow: authorization URL generation with PKCE, callback handling, token exchange, encrypted storage, and automatic refresh.

  1. Your backend creates an auth session via the SDK.
  2. You redirect the user to the authorization_url.
  3. The user authorizes with the provider (e.g., Google, Slack).
  4. The provider redirects to Authpipe’s callback URL.
  5. Authpipe exchanges the code for tokens, encrypts and stores them.
  6. Authpipe redirects the user to your redirect_url.
  7. Your backend calls getCredential to retrieve a valid token.

Before users can connect, register your OAuth app credentials.

const config = await authpipe.createProviderConfig({
provider_id: "slack",
client_id: "your-slack-client-id",
client_secret: "your-slack-client-secret",
oauth_redirect_url: "https://api.authpipe.dev/oauth/callback",
attachment: "user", // or "tenant"
enabled: true,
scopes: ["channels:read", "chat:write"],
});

The oauth_redirect_url must be https://api.authpipe.dev/oauth/callback (or your self-hosted equivalent) and must match what you registered in the provider’s developer console.

When a user initiates a connection, create an auth session and redirect them.

const session = await authpipe.createAuthSession({
provider: "slack",
tenantId: "org_acme",
userId: "user_jane",
redirectUrl: "https://yourapp.com/integrations/callback",
scopes: ["channels:read", "chat:write", "users:read"], // optional override
});
// Redirect user to session.authorization_url

Parameters:

ParameterRequiredDescription
providerYesProvider slug (e.g., "slack", "google")
tenant_idYesYour tenant identifier
redirect_urlYesWhere to send the user after OAuth completes
user_idNoEnd-user identifier (required for user-attached providers)
scopesNoOverride scopes for this session
installation_idNoLink this connection to an existing installation
template_variablesNoPer-session template values (e.g., {"shop": "acme-store"} for Shopify)

You don’t need to implement a callback endpoint. Authpipe handles the OAuth callback at oauth_redirect_url, exchanges the authorization code for tokens, encrypts and stores them, then redirects the user to your redirect_url.

After the redirect, you can optionally check the connection status:

const connections = await authpipe.searchConnections({
filter: {
tenant_id: { eq: "org_acme" },
user_id: { eq: "user_jane" },
},
sort: [{ field: "connected_at", direction: "desc" }],
limit: 1,
});
const connection = connections.data[0];
console.log(connection.status); // "active"

Once a connection exists, call getCredential to get a valid access token.

const { credential, source, scopes } = await authpipe.getCredential({
provider: "slack",
tenantId: "org_acme",
userId: "user_jane",
});
// credential is a valid access token
// source is "connection" or "installation"

If the token is expired, Authpipe refreshes it transparently before returning.

If a user re-authorizes (e.g., to upgrade scopes), Authpipe upserts the existing connection rather than creating a duplicate. The tokens and scopes are updated in place.

await authpipe.deleteConnection("conn_abc123");

This sets the connection status to revoked. The connection can be reactivated if the user re-authorizes.