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.
Flow overview
Section titled “Flow overview”- Your backend creates an auth session via the SDK.
- You redirect the user to the
authorization_url. - The user authorizes with the provider (e.g., Google, Slack).
- The provider redirects to Authpipe’s callback URL.
- Authpipe exchanges the code for tokens, encrypts and stores them.
- Authpipe redirects the user to your
redirect_url. - Your backend calls
getCredentialto retrieve a valid token.
Configure a provider
Section titled “Configure a provider”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"],});config, err := client.CreateProviderConfig(ctx, &authpipe.CreateProviderConfigParams{ ProviderID: "slack", ClientID: "your-slack-client-id", ClientSecret: "your-slack-client-secret", OAuthRedirectURL: "https://api.authpipe.dev/oauth/callback", Attachment: "user", Enabled: true, Scopes: []string{"channels:read", "chat:write"},})config = client.create_provider_config( 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", 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.
Create an auth session
Section titled “Create an auth session”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_urlsession, err := client.CreateAuthSession(ctx, &authpipe.CreateAuthSessionParams{ Provider: "slack", TenantID: "org_acme", UserID: "user_jane", RedirectURL: "https://yourapp.com/integrations/callback", Scopes: []string{"channels:read", "chat:write", "users:read"},})session = client.create_auth_session( provider="slack", tenant_id="org_acme", user_id="user_jane", redirect_url="https://yourapp.com/integrations/callback", scopes=["channels:read", "chat:write", "users:read"],)Parameters:
| Parameter | Required | Description |
|---|---|---|
provider | Yes | Provider slug (e.g., "slack", "google") |
tenant_id | Yes | Your tenant identifier |
redirect_url | Yes | Where to send the user after OAuth completes |
user_id | No | End-user identifier (required for user-attached providers) |
scopes | No | Override scopes for this session |
installation_id | No | Link this connection to an existing installation |
template_variables | No | Per-session template values (e.g., {"shop": "acme-store"} for Shopify) |
Handle the callback
Section titled “Handle the callback”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"resp, err := client.SearchConnections(ctx, &authpipe.SearchRequest{ Filter: map[string]map[string]interface{}{ "tenant_id": {"eq": "org_acme"}, "user_id": {"eq": "user_jane"}, }, Sort: []authpipe.SortDirective{{Field: "connected_at", Direction: "desc"}}, Limit: 1,})from authpipe.types import SearchRequest, SortDirective
resp = client.search_connections(SearchRequest( filter={"tenant_id": {"eq": "org_acme"}, "user_id": {"eq": "user_jane"}}, sort=[SortDirective(field="connected_at", direction="desc")], limit=1,))Retrieve credentials
Section titled “Retrieve credentials”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"result, err := client.GetCredential(ctx, &authpipe.GetCredentialParams{ Provider: "slack", TenantID: "org_acme", UserID: "user_jane",})// result.Credential, result.Sourceresult = client.get_credential( provider="slack", tenant_id="org_acme", user_id="user_jane",)# result.credential, result.sourceIf the token is expired, Authpipe refreshes it transparently before returning.
Re-authorization
Section titled “Re-authorization”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.
Revoking connections
Section titled “Revoking connections”await authpipe.deleteConnection("conn_abc123");err := client.DeleteConnection(ctx, "conn_abc123")client.delete_connection(connection_id="conn_abc123")This sets the connection status to revoked. The connection can be reactivated if the user re-authorizes.