Native apps: Sign in with Every App
How a Mac or phone app signs a person in to one EveryApp app through the Gateway's OAuth server: bearer routes (`public` entries with `bearer: true`), the client contract (discovery, registration, loopback redirect, PKCE, resource, refresh, sign-out), and Cloudflare Access.
A native app (a Mac recorder, a phone client) signs the person in through the Gateway's sign-in page in the system browser and gets a token that opens one app, as that member, and nothing else. It's an OAuth client of the Gateway like an AI client, except its resource is the app's origin (https://notes.apps.example.com) instead of /mcp. No password or cookie reaches it. The person's page is /docs/native-sign-in.
The app's side
// everyapp.config.ts
public: [{ path: "/api/**", bearer: true }],A bearer route takes a token on every method (so no methods) and refuses the session cookie, so keep the web UI's calls elsewhere. Behind Cloudflare Access, access on lets these paths and /.well-known/oauth-protected-resource through Access on the app's host; deploy updates Access when it adds a bearer route. In the handler a native caller is an ordinary member with channel: "api", actor.sub oauth:<connection id> and scopes: ["*"].
The client contract
{origin} is the app's URL, {gateway} the Gateway's.
- Ask for the app's URL; keep the origin; require https.
- Discover:
GET {origin}/.well-known/oauth-protected-resourcegivesresource(must equal{origin}) andauthorization_servers[0]. ThenGET {gateway}/.well-known/oauth-authorization-servergives the endpoints. - Be a client: register once per install at
registration_endpoint(client_name,redirect_uris: ["http://127.0.0.1/callback"],grant_types: ["authorization_code", "refresh_token"],token_endpoint_auth_method: "none"), keepingclient_id. Or publish a Client ID Metadata Document and use its URL asclient_id. Registration lapses after 60 days unused (invalid_client: register again). - Listen on a free port on
127.0.0.1, path/callback. - Open the system browser (never a web view) at
{authorization_endpoint}?response_type=code&client_id=…&redirect_uri=http://127.0.0.1:{port}/callback&code_challenge={S256}&code_challenge_method=S256&state={random}&resource={origin}. Noscope. The person signs in and allows. - On the callback, check
stateandiss, thenPOST {token_endpoint}withgrant_type=authorization_code,code,redirect_uri,client_id,code_verifierandresource={origin}. That returns an access token (1 hour) and a refresh token.invalid_targetmeans the Gateway has no such app. - Call
{origin}/…withAuthorization: Bearer {access_token}. - Refresh with
grant_type=refresh_token&refresh_token=…&client_id=…&resource={origin}. Store the new refresh token at once (rotation).invalid_grantmeans sign in again. - Sign out:
POST {revocation_endpoint}with the refresh token. - Keep tokens in the Keychain, never log them, and show which host the person is signed in to.
What a token opens
Only {origin}; another app host or /mcp refuses it. It acts as the member who consented, re-checked on every request. Scope *; there's no read-only native grant. The grant ends when the person revokes it (Your connections → Accounts → Apps on your devices), the app signs out, the member is removed, the app is deleted, or 30 days pass unused. MCP_OAUTH_ENABLED and MCP_DCR_ENABLED switch native sign-in along with MCP's OAuth.
Behind Cloudflare Access
The person passes Access's login in the browser at step 5; the token and registration endpoints are let through already. On the app's host only its bearer routes, its other public routes and the discovery document are let through, so a native app that gets HTML back should tell the person to ask the operator to add the path as a bearer route (and run access on).
In development, everyapp dev's stub mode treats any bearer as the dev user. Test real tokens against a deployed Gateway.
Agent tools: write, connect and debug them
How an app's AI tools work end to end: defineTools() in src/tools.ts field by field (names, risk, context, results, errors, limits), how the Gateway snapshots and serves them, MCP apps, the dev connector, connecting a person, and troubleshooting missing tools, 401s and 403s.
The deploy pipeline
What everyapp deploy does from its first line to Live, what can stop it, what a redeploy keeps, renaming an app (previousIds), releases (release, install), browser installs, and delete.