Overview
Connections are credentials a user holds for an external service (Linear, GitHub, Slack, …). Your app declares how those credentials are obtained — a connection provider — and consumes them at runtime to make authenticated calls to the third-party API. OAuth 2.0 is built in, either with a client you register yourself (oauth) or discovered from the service (oauth-discovery). Services that authenticate with a token the user copies from their settings use an api-key provider. Services with their own connection flow — a hosted login page, an account id delivered by webhook — use a custom provider, where your app drives the flow and Twenty keeps the user, the workspace and the saved connection. Future credential types (basic auth) will plug into the same surface — apps already using defineConnectionProvider({ type: 'oauth', ... }) won’t need to migrate.
defineConnectionProvider
Declare how your app's connections are obtained
defineConnectionProvider
Declare how your app's connections are obtained
WORKSPACE provider (the default), a member clicks “Add connection” in your app’s settings, completes the provider’s consent screen, and a ConnectedAccount row is created in their workspace. See “Workspace or personal connections” for USER providers.A working setup needs two files — the connection provider, and a matching serverVariables declaration on defineApplication that holds the OAuth client credentials.nameis the unique identifier string used inlistConnections({ providerName })(kebab-case, must match^[a-z][a-z0-9-]*$).displayNameshows in the app’s Overview tab and in the AI tool list.scopedecides who connects:'WORKSPACE'(the default) for connections shared with the whole workspace,'USER'for connections each member makes for themselves. See “Workspace or personal connections” below.logois a path to an asset bundled in your app’spublic/folder, served through the app’s public assets. It is shown on the “Connect with” row; when omitted, the row shows no logo.clientIdVariable/clientSecretVariableare names, not values — they must match keys declared indefineApplication.serverVariables. The actualclient_idandclient_secretare entered by the server admin through the app registration UI, never committed to your repo.- The client secret is only used by Twenty to exchange and refresh tokens: it is never passed to your logic functions, and
process.env[clientSecretVariable]is undefined there. The client ID is still available. - Use
serverVariables(notapplicationVariables) — OAuth credentials are server-wide and one OAuth app per Twenty server. - Until both
serverVariablesare filled in, the app’s Overview tab shows a “needs server admin” hint and the “Add connection” button is disabled. typeis'oauth'(with anoauthblock),'oauth-discovery'(with anoauthDiscoveryblock, see below),'custom'(with acustomblock, see “Custom connection flows”) or'api-key'(no block, see “API key connections”). The discriminator is forward-compatible: future types will add new sub-config blocks alongside these.
type: 'oauth-discovery' with oauthDiscovery: { resourceUrl }, an HTTP or HTTPS URL. At connect time Twenty discovers the authorization server from the resource (RFC 9728), identifies itself with its client metadata document when the server supports it, otherwise registers a client dynamically, and refreshes tokens like any OAuth connection. No serverVariables are needed. Discovery ships with Twenty 2.59.0: if your app declares an oauth-discovery provider, declare "engines": { "twenty": ">=2.59.0" } in its package.json.The OAuth callback URL your provider needs to whitelist is:API key connections
Connect services that authenticate with a token
API key connections
Connect services that authenticate with a token
type: 'api-key'; there is no config block:getConnection returns it as accessToken, with providerType: 'api-key'. Twenty never refreshes or revokes it: when the service rejects it, call reportConnectionAuthFailure so the member is asked to reconnect with a new one.Declare an identifyAccountLogicFunctionUniversalIdentifier (see “Identify the connected account”). It runs with the pasted key as accessToken before anything is saved, so one call to the service’s “who am I” endpoint both checks the key and names the connection. If it throws, the key is rejected and the member sees the error. Without it, any non-empty key is saved and the connection is named after the member’s email.API key providers ship with Twenty 2.59.0: declare "engines": { "twenty": ">=2.59.0" } in your app’s package.json.Custom connection flows
Connect services that are not OAuth providers
Custom connection flows
Connect services that are not OAuth providers
type: 'custom' and two logic functions:...UniversalIdentifier: '<uuid>'. The earlier { universalIdentifier: '<uuid>' } object form (for example onConnectLogicFunction: { universalIdentifier }) is deprecated: it is still accepted, but will be removed in a future release.callbackUrl that carries it. Return where to send the user:callbackUrl to the service unchanged. Twenty accepts it as a browser redirect (GET) and as a server notification (POST), and runs the callback logic function for each request with its method, query parameters (without state), headers, parsed body and rawBody (the exact request bytes, null on GET). Return the account the request proves, or null when it carries none — typically the browser coming back while the account id travels by notification:callbackUrl only proves the request carries that URL, not that the service sent it. When the service signs its notifications, verify the signature over rawBody before trusting the body. Headers are lowercased, and cookie, authorization and proxy-authorization are never passed on:onDisconnectLogicFunctionUniversalIdentifier.A provider’s type, like its scope, cannot change once it is synced: to move a service between oauth, oauth-discovery, custom and api-key, declare a new provider with a new universalIdentifier.Custom providers ship with Twenty 2.52.0.Identify the connected account
Stop a reconnect from silently switching upstream accounts
Identify the connected account
Stop a reconnect from silently switching upstream accounts
identifyAccountLogicFunctionUniversalIdentifier to a logic function in the same app that returns a stable id for the account behind the freshly issued token:timeoutSeconds at 10, whatever the manifest declares; keep it to a single request to the provider’s “who am I” endpoint. The on-connect hook, if any, still runs afterwards, once the connection is saved.Payload. The handler receives the provisional access token. It has not been persisted yet, so getConnection cannot return it; use it directly and do not log it.idToken is the raw id_token of an OpenID Connect provider, for providers that identify the account in its claims instead of behind a “who am I” endpoint. Twenty received it straight from the provider’s token endpoint over TLS, the case in which OpenID Connect lets a client rely on the connection instead of the signature, so Twenty does not verify the signature and sends no nonce. Decode it and check iss and aud before trusting a claim. It ships with Twenty 2.67.0: if your function reads it, declare "engines": { "twenty": ">=2.67.0" } in the app’s package.json.Result. Return the account’s id, and optionally a handle to display:externalAccountIdmust be stable for the life of the upstream account (a team id, an organization id, a user id), never a name the user can change. Twenty trims it and stores it on the connection on first connect.handle, when returned, replaces the handle Twenty would otherwise derive (the OIDCid_tokenemail, or the connecting user’s email). Return something a user recognizes, such as the Slack workspace name.name, when returned, names the connection when it is created, instead of<displayName> #<n>. A reconnect keeps the existing name.name, here and in the custom callback result, ships with Twenty 2.66.0: if your app returns it, declare"engines": { "twenty": ">=2.66.0" }in itspackage.json.- Return
{ externalAccountId: null }when the provider has no stable id to offer. Twenty then behaves as if no identify function were declared: no id is stored, a reconnect clears any id stored earlier, and reconnects are not checked. A barenullor a missing return is treated as an error, so a handler that forgets to return cannot silently disable the check. - If the function throws, times out, or returns anything else, the connection is not saved and the user lands back on the settings page with an error. Throw only when you genuinely cannot identify the account.
externalAccountId with the one stored on the connection. If they differ, the callback is refused before anything is written: the existing tokens, handle and scope stay as they were, the on-connect hook does not run, and the user sees which account they authorized and which one the connection belongs to. Connections created before your app declared the function have no stored id yet; their next reconnect stores it.Twenty does not deduplicate on externalAccountId: connecting the same upstream account twice through Add connection creates two connections. The id is exposed on listConnections and getConnection, so an app that wants one connection per upstream account can detect duplicates itself (for instance in its on-connect hook).Writing the function. Most providers expose a single endpoint that describes the current token. For Slack that is auth.test, which returns the workspace (team_id, team) and the user behind the token:String(id).Identification ships with Twenty 2.48.0. If your app relies on it, declare "engines": { "twenty": ">=2.48.0" } in its package.json.Check what a connection can reach
Tell members when a connection needs more access
Check what a connection can reach
Tell members when a connection needs more access
getConnection(connectedAccountId) to get a fresh token. Twenty rate-limits it per member and provider.WARNING or ERROR marks the connection’s row as needing action and shows the title, description and action as a banner above the connections. action.location may be a path inside Twenty or an https URL on the provider’s own hosts (its OAuth endpoints, or its resource URL for oauth-discovery), so you can send the member to install your app or grant consent at the provider; any other link is dropped. If the check throws or returns anything else, nothing is shown, so throw rather than guess when the provider cannot answer.The field ships with Twenty 2.66.0: declare "engines": { "twenty": ">=2.66.0" } in your app’s package.json when you use it.Run a logic function on connect
React the moment a connection is established
Run a logic function on connect
React the moment a connection is established
team_id that inbound events will be keyed by. Set onConnectLogicFunctionUniversalIdentifier to reference a logic function in the same app (by its universalIdentifier), and it runs right after the ConnectedAccount is created.getConnection(connectedAccountId) to read the fresh access token and call the provider’s API (e.g. Slack auth.test) or persist a mapping with the key-value store.Run a logic function on disconnect
Clean up when a connection is disconnected or removed
Run a logic function on disconnect
Clean up when a connection is disconnected or removed
team_id on connect, for instance, has to release that claim so another workspace can connect the same Slack team. Set onDisconnectLogicFunctionUniversalIdentifier to reference a logic function in the same app, and it runs when the connection is disconnected and again when it is deleted.ConnectedAccount and its token are still present, so getConnection(connectedAccountId) resolves and the handler can release whatever it registered remotely. On a delete the credentials may already be gone (a member can delete a connection they disconnected earlier), so make the handler idempotent and keep the state it needs (a team_id, an external subscription id) in the key-value store, written at connect time and keyed by connectedAccountId. Keep it short: it runs inside the request, so its timeoutSeconds is the upper bound on how long that request can take.The hook fires when a connection is disconnected or removed on its own. Uninstalling the app drops its connections through a database cascade instead, so the hook does not run there. Declare an uninstallLogicFunction on defineApplication for that path: it runs before the app’s metadata is deleted, so it can still call listConnections and clean up whatever is left.listConnections / getConnection
Use connections from a logic function
listConnections / getConnection
Use connections from a logic function
listConnections({ providerName }) returns this app’s ConnectedAccount rows for the given provider, with refreshed access tokens.- Pass
{ providerName }to filter by provider; omit it to get all connections this app owns across all providers. - The server transparently refreshes the access token before returning. Your handler always sees a usable token (or
authFailedAtset). getConnection(id)is the single-row equivalent.
reportConnectionAuthFailure
Tell the platform a credential is dead
reportConnectionAuthFailure
Tell the platform a credential is dead
authFailedAt on its own only when an OAuth refresh fails. Providers whose tokens are never refreshed (a Slack bot token, for example) fail only at call time inside your handlers, so the connection row in settings would keep showing Connected while every call dies. When your code hits a definitive auth rejection, report it:authFailedAt and the optional reason on the connection. The settings row flips to Reconnect needed with a Reconnect button, the connection detail page shows the reason, and getConnection starts throwing AppConnectionAuthFailedError for that row. The flag and reason clear automatically when the user reconnects. A reason longer than 1000 characters is rejected, so truncate provider payloads before passing them.Only report failures that a reconnect would actually fix (an invalid_auth-class rejection from the provider), never transient network errors. An app can only report its own connections, and a request user can only report their own personal credentials.The mutation behind this helper ships with Twenty 2.40.0, so calling it against an older server fails. If your app uses it, declare the dependency in your package.json: "engines": { "twenty": ">=2.40.0" }.Workspace or personal connections
Choose who connects with the provider scope
Workspace or personal connections
Choose who connects with the provider scope
- Workspace shared (
'WORKSPACE') — any workspace member can use the credential. Cron / database triggers also see it, since they have no request user. - Just for me (
'USER') — the credential belongs to the connecting member. In runs made on a member’s behalf (HTTP-route trigger withisAuthRequired: true),listConnectionsreturns the shared connections plus that member’s own, andfindConnectionForRequestpicks the member’s personal connection, falling back to a shared one when they have none. In runs without a request user (cron triggers, for example),listConnectionsreturns every connection, including every member’s personal ones.
scope decides which one its new connections get:scope: 'WORKSPACE'(the default) — the app works with connections shared with the workspace. Add connection in the app’s workspace settings creates a workspace-shared connection.scope: 'USER'— each member connects their own account, creating personal connections. Members add, reconnect and remove them from the app’s page under Settings > User > Apps preferences, which requires the User Apps permission. The app’s workspace settings have no Add connection button for aUSERprovider.
USER connection, so do not rely on one for
a feature every workspace needs now.scope of an existing provider, and the upgrade is refused if it tries. To move a service from one scope to the other, declare a new provider with a new universalIdentifier and drop the old one. Upgrading then deletes the old provider and every connection made with it through the regular disconnect path (onDisconnectLogicFunctionUniversalIdentifier, token revocation, channel cleanup), and members connect again through the new provider.Adding or reconnecting a Just for me connection requires the User Apps permission, and adding or reconnecting a Workspace shared one requires the Workspace Apps permission.Use the right connection for each handler:scope, declare "engines": { "twenty": ">=2.49.0" } in its package.json. In the same version a connection’s scope replaces its visibility, which stays available as a deprecated lowercase alias. listConnections and getConnection from twenty-sdk 2.49.0 read scope, so apps built with it need a 2.49.0 server.One-time provider setup
Register your OAuth app with the third-party service
One-time provider setup
Register your OAuth app with the third-party service
- Go to the provider’s developer settings (e.g. https://linear.app/settings/api/applications/new).
- Set the Redirect URI to
<SERVER_URL>/auth/apps/callback. - Copy the generated Client ID and Client Secret.
- Open the installed app in Twenty as a server admin → set the values on the corresponding
serverVariables. - Workspace members can then add connections to
WORKSPACEproviders from the per-app Connections section.