# Connecting a standalone workspace app

Tamloot, forms builders and other reviewed standalone services run their own
code and keep provider credentials and execution state outside Retainer. A
workspace admin first approves a release with `execution: 'standalone'`, its
schema/views and read/write access. The app then connects to that installation.

In accounts mode, register an OAuth client through the authorization server's
metadata and registration endpoint. Explicitly request the protected resource
`https://your-retainer-host/v1` in the registration's `resources` array. Pin the
returned client ID in the operator's reviewed manifest as `oauthClientId`, then
publish and install that release. The ID is included in the review digest and
must remain the same across releases of the registration. Register exact callback
URLs and use authorization code with state and PKCE S256.

Request the same `/v1` resource and explicit `read`, `write` and, when needed,
`offline_access` scopes during authorization and code exchange. The consent page
lets an admin choose an active reviewed installation in a workspace they manage.
It shows the app's actor and requested access. MCP uses a separate `/mcp` audience
and person-bound consent; its tokens cannot be used for the standalone REST flow.

Use the access token as a bearer credential with REST or the SDK:

```ts
import { RetainerClient } from '@retainer/sdk';

const retainer = new RetainerClient({
  baseUrl: 'https://your-retainer-host',
  apiKey: accessToken, // Historical option name; accepts the REST OAuth bearer token.
});
```

Store refresh tokens securely in the standalone service, serialize refresh and
persist rotated tokens. Tokens and installation keys bind to the installation's
grant, not its release. A release upgrade that keeps the same actor and scopes,
and an ordinary settings change, keep them working. Disable, uninstall, a change
of actor or scopes (up or down) and a reconnect revoke them; the app then needs a
new human connection or key. The
SDK does not refresh OAuth tokens itself. Recreate its client with the current
access token after refresh. In key mode, an admin creates an installation key
in Extensions, chooses the approved scope subset and copies its shown-once value
into the service instead.

Writes are attributed to the installation's approved integration or agent actor.
They have workspace-wide access within their approved coarse scopes, without
personal memory or people/key administration. Installer membership changes do
not remove the workspace grant. Hard account deletion can remove library refresh
tokens and require another admin's approval. Admins inspect and revoke credentials
in Extensions; revocation drains admitted API writes. Already-issued short-lived
file URLs retain their documented expiry window.

For a forms submission, own a permanent submission ID in the external service,
map it to a Retainer record/event ID and send stable request idempotency keys
on retries. Retainer's request receipts expire; keep the permanent mapping in
the service. For a Tamloot transcript, create an upload intent, PUT the complete
bytes, finalize, then attach the immutable file ID to the ordinary event/record
write. File ownership and the change feed identify the installation.

Ordinary `logEvent` does not replace a changed payload under an existing event ID.
Keep edit/revision policy explicit in the standalone service. Managed-source
attestation, participant matching, source suppression and atomic source revision
imports require a reviewed hosted adapter and its live lease. An OAuth token does
not fabricate that lease or grant the hosted queue/KV/secret broker APIs.

To give the workspace's members a way in, declare a sidebar link in the
release ([extensions.md](https://github.com/Tamloot-cc/Retainer/blob/main/docs/specs/extensions.md) §8). Members open the app from
Retainer's sidebar and are signed in with their Retainer account through an
OpenID Connect flow, so the app needs no login of its own. The ID token carries
the person, the workspace, their role and the installation. Use it for identity
only; the app's API access stays its installation credential. This needs
accounts mode.

To let routines call the app, include hosted `tool` functions in the same
release ([extensions.md](https://github.com/Tamloot-cc/Retainer/blob/main/docs/specs/extensions.md) §8). Each tool calls the app's own
API with a shared key. The app generates that key during its connection flow
and writes it, with its own API address, to the installation's generated secret
setting using its own credential, so the admin does not copy anything. Tools
stay unavailable until that secret exists and the credential is live. The app
records the tool call ID as its idempotency key and as the actor; Retainer's run
log names the routine behind it. When a tool call leads to a later write, send
that call ID as `Retainer-Caused-By`, so the write cannot trigger the routine
that called the tool ([extensions.md](https://github.com/Tamloot-cc/Retainer/blob/main/docs/specs/extensions.md) §9.4). On Compose, a
private app address must be listed in `RETAINER_EXECUTION_API_ORIGINS`.

Hosted infrastructure and live provider acceptance are separate launch steps;
local OAuth and fixture tests do not establish deployment or provider access.
