onTokens().
Basic OAuth
Declaration
Scope separator
The transport sendsscopes in the authorize URL’s scope parameter joined with a space, as RFC 6749 specifies. Some providers document another separator: Linear’s authorize endpoint takes a comma-separated list. Declare scopeSeparator: ',' for one of those (the only other accepted value), on the main connection and on each named one that needs it:
ekanos dev sends the same value, so the local OAuth loop matches the host. Declaring scopeSeparator needs @ekanos/cli and @ekanos/sdk releases that know the field; an older ekanos validate reports it as an unrecognized key.
Token endpoint client authentication
provider.tokenAuthMethod says how the token endpoint expects the client to authenticate. It defaults to 'client_secret_basic': an HTTP Basic Authorization header. Set 'client_secret_post' for a provider that wants client_id and client_secret in the form body instead and rejects Basic. LinkedIn is one. Check the provider’s docs for which it accepts; a mismatch shows up as exchange_failed, and the provider’s (redacted) response is in the host and harness logs.
Endpoints
Both must be HTTPS and covered by youregress allowlist. defineIntegration() rejects the definition otherwise, telling you which origin to add.
redirectUri — the schema is .strict() and rejects it. The host owns the callback route and builds the URI from its own origin.
The host serves these routes for every partner integration that declares oauth:
state, so renaming the package or its namespace never breaks a provider app registered against it. ekanos apps show <product> prints the exact URI for each Source.
A provider app set up before the host recorded redirect URIs uses the older per-integration URL, https://<your-ekanos-host>/api/integrations/<your-slug>/oauth/callback. The host keeps serving it and keeps sending it for that app, so nothing breaks. ekanos apps show labels it, and ekanos doctor reports it as drift because it stops matching if the slug or namespace changes.
The code exchange runs through your integration’s allowlisted ctx.fetch, authenticating to the token endpoint with HTTP Basic client auth unless provider.tokenAuthMethod says otherwise, and then calls onTokens(ctx, tokens) with the real capability context.
Client helpers
Reference the routes through@ekanos/sdk/hooks rather than spelling them yourself: pass partnerOAuthConnectPath(slug) as OAuthActivationForm’s connectPath, createPartnerConnectionCheck(slug) as its checkConnection, and partnerOAuthErrorParam(slug) as its errorParam. See Activation form.
On failure the callback appends <slug>_oauth_error=<code> to the return URL. partnerOAuthErrorParam maps the codes to messages:
wrong_workspace, app_not_set_up and organization_access were added in 0.4.0. In short: wrong_workspace means the person consented in a different account or workspace than the integration is configured for; app_not_set_up means the provider refused the configured OAuth app (its client or scopes); organization_access means organization-wide access was granted where the integration only takes a person’s own access. The apostrophes in those messages are typographic (’), so match ticket text accordingly.
Tokens object
accessToken are optional. onTokens runs after the code exchange. The contract also covers refreshes, but the host does not drive token refresh yet — see Limitations.
Common patterns
Store tokens separately
Log for audit
Extra authorize parameters
Some providers need parameters beyond the standard ones. Declare them on the provider:client_id, redirect_uri, response_type, scope, state and the PKCE parameters itself; declaring any of them is an error.
A second connection
oauth is the integration’s main connection. Declare more under oauthConnections, each with its own app, scopes and tokens. Linear’s agent is one: an app-actor grant the team turns on separately, while the main connection serves widgets and tools.
/api/integrations/<slug>/oauth/connect?connection=agent. The callback URL is the same for every connection. Ids are kebab-case; default is the main oauth.
A named connection is the team’s unless it declares level: 'user' (one with a teamApp is always the team’s). A team-level named connection never stands in for the main one: a team that has connected only agent has not connected the integration itself, and an experience that uses the integration still asks the team to connect. A level: 'user' named connection is one each person connects for themselves, and it serves that person’s invoker calls like a per-person main connection.
To put a second connection’s Connect button in your own activation form, pass its id to OAuthActivationForm and to the status check, so both name the same connection:
label. Each runs that connection’s loop with its own app, scopes and authorizationParams, and the callback runs that connection’s onTokens. Each connection shows whether it is connected and has its own Disconnect, which forgets only its tokens. A teamApp connection’s fields are saved with your other local keys in .ekanos/local-secrets.json.
The team brings its own app
By default a super-admin configures one OAuth app per Source. DeclareteamApp on a connection and each team supplies its own instead:
source_admin) fills these in. Ekanos stores them as the team’s credentials, which win over the Source’s for that team only, and shows the callback URL and the team’s webhook URL to paste into the provider. fields must include the connection’s client id and secret, and may add the signature secrets your webhooks declare and the placeholders of your endpoint URLs (below). Nothing else.
Setup instructions
Someone has to create your connection’s app in the provider’s console: the Source’s admin for the Source’s app, or each team when you declareteamApp. Tell them how with setup, on the connection:
{callbackUrl} with the exact redirect URI to register and {scopes} with your declared scopes, so the steps never go stale. They appear wherever the app gets set up:
ekanos apps showandekanos apps set, which a Source admin uses for the Source’s appekanos catalog, under the setup step for each app- the team’s setup panel in the app, for a
teamAppconnection
steps takes 1 to 12 sentences, each under 400 characters. consoleUrl and guideUrl are optional https URLs. Write what the provider’s console calls things. ekanos validate warns about a connection with no setup.
This is separate from oauth.setup in harness.config.ts, which is the local checklist the harness shows while you develop.
One OAuth server per customer
Some providers run a separate OAuth server for each customer. Zendesk is one: every account authorizes athttps://<subdomain>.zendesk.com/oauth/.... Write those labels of the hostname as {field} placeholders, and declare a teamApp field of the same name so the team enters its value with its app:
- A placeholder is a whole hostname label.
{sub}.zendesk.comis valid;x{sub}.zendesk.com, a placeholder in the path, the query or the port is not. - At least two literal labels follow the last placeholder, so the team picks its account on the provider, never the provider.
- Each placeholder names a
teamAppfield withsensitive: false. Its value is part of a URL, not a secret. - A placeholder can’t share its name with the client id, the client secret or a webhook signing secret.
- Egress is checked with the placeholders filled with two different sample labels, so only a wildcard covers it (
https://*.zendesk.com).
-- in the third and fourth places); it is lowercased, and anything else (acme.evil.com, acme/, an empty value) fails as not_configured rather than being escaped.
Every field is also readable as ctx.secrets.get('zendesk_subdomain'), so tools and your own token refresh build the same host. resolveOAuthUrl() from @ekanos/sdk/integration applies the transport’s rules:
onTokens and build API calls from that copy, so a token is only ever sent to the host that issued it.
In the harness, the placeholder sits in .ekanos/local-secrets.json beside the client credentials.
Connection levels
connection.levels states who connects your integration: 'source', 'team' and/or 'user' (each person on their own). Prefer declaring a level on each credential (oauth.level, oauthConnections.<id>.level, activation.credentials) and leaving connection.levels out: the contract then derives it from them. With neither, the contract infers it from proposes: ['user'] for credentialModel: 'user', ['source'] for credentialModel: 'source', else ['user'] for scope: 'user', else ['team']. See Credential levels.
connection: { levels: [...] } still wins, with a warning when it disagrees with the credential levels.
What it does:
- It is part of your contract, so dropping a level is a breaking change in the contract diff and adding one is compatible.
- The host serves each level. A
'team'credential is connected once by a team admin and stored on the team. A'user'credential is connected by each person and stored on their personal account. See Credential levels. ekanos checkand the experience admission checks hold an experience’smodesfor your integration to it. An experience whose only modes areinvokeroruserfails when the levels lack'user'; besideteam, or forteamwithout'team', it is a warning.ekanos validateand the integration admission checks warn whenproposes.scopeis not one of the levels, and note each credential declared at'user'.
Per-person sign-in
Declarelevel: 'user' on oauth and each member signs in for themselves. A member needs no admin permission. The connect dialog lists it under For you.
onTokens gets a context on the account that owns the credential, so ctx.connection?.owner === 'user' and ctx.secrets.set writes the person’s own tier. Write it the same way as for a team credential. ctx.secrets there also reads the app’s client id and secret, which the Source’s admin issues; the person never sees them.
On a later call made for that person, their tokens are on ctx.identity.secrets, and the app’s client credentials are still on ctx.secrets. Refresh against the person’s tier and write back to it:
ctx.identity is absent on a machine call, so a schedule or team workflow cannot refresh or use a person’s token. A super-admin can switch per-person credentials off for a Source; then nobody there can connect their own.
Limitations
Known gaps in the hosted flow:- A person’s credential is never used by a team workflow, schedule, webhook, health check, workflow agent mode or managed agent (see Credential levels)
- No host-driven token refresh.
onTokensruns after the code exchange only; refresh in your own code (below) - No partner disconnect hook: nothing runs in your integration when a team disconnects, so a provider-side token is not revoked
- Token-endpoint client authentication is HTTP Basic or
client_secret_postonly (noprivate_key_jwt) - A team can supply only a connection’s client credentials, its endpoint placeholders and webhook signing secrets (
teamApp) - An endpoint placeholder fills a hostname label only, never a path or a whole host
Refreshing tokens yourself
Your code can read the connection’s client credentials:ctx.secrets.get(credentials.clientIdSecretName) and ctx.secrets.get(credentials.clientSecretSecretName) return the Source’s app, or the team’s own app for a teamApp connection, exactly as the host uses them for the code exchange. Refresh when a call returns 401 or the stored expiry has passed, and write every value the provider returns before using the new access token. A provider that rotates refresh tokens on every refresh (Linear does) invalidates the old one, so a refresh whose new refresh token is not stored loses the connection:
onTokens is also an ordinary async function, so you can unit-test it directly against createMockContext():
Troubleshooting
Endpoint origin not covered by egress
defineIntegration() reports, for example, oauth.provider.tokenUrl: its origin https://connect.acme.example is not covered by this definition's egress list [...] and names the origin to add. Both provider.authorizationUrl and provider.tokenUrl must have their origins in your egress list:
Connect fails with not_configured
The host could not resolve the client credentials named byclientIdSecretName / clientSecretSecretName. Those names are strings you choose; the values are credentials an administrator adds for your workspace, not fields a user enters. Ask an administrator to add them under the exact names your declaration uses.
For a connection with endpoint placeholders, the same code means a placeholder’s value is missing or is not a single hostname label. The host logs which (missing / invalid).
Next steps
- Activation form — the
OAuthActivationFormvariant - Capability context — use ctx in onTokens