Your service behind a portal
Listen
Plain HTTP/1.1 on
127.0.0.1:<port>inside the machine, where<port>is the portal’s guest port (default 8080). The edge terminates TLS; your service needs no certificate.Listening on
127.0.0.1is enough and is the safest choice: the edge reaches the port through the machine’s tunnel, and nothing else should.WebSocket upgrades pass through (checked once).
Run it as a service so it comes back after the machine is suspended or restarts, for example
/etc/vmagent/services.d/app.json:{"argv": ["/usr/bin/myapp", "--listen", "127.0.0.1:8080"], "restart": "always"}
Paths you never see
The edge answers these itself or sends them to the auth service; requests for them never reach your service:
| Path | Who answers |
|---|---|
/robots.txt | the edge (Disallow: /), or the portal’s bucket when it has one |
| your developer MCP path, if on | your service, but only for your project’s developers’ API keys |
/_portal/… | auth service: sign-in, sign-up, sign-out, tokens, refresh |
/_space/… | auth service: the Spacebar’s script and report panel |
/oauth/… | auth service: the OAuth server for MCP and API clients |
/.well-known/oauth-authorization-server… | auth service |
/.well-known/oauth-protected-resource… | auth service |
/.well-known/openid-configuration | auth service |
Every other path is yours, and every one of them requires a signed-in user, unless the
portal has anonymous access on. The one exception is the
sign-up approval call, which the auth service makes itself, as kind: "service" rather than as a user: don’t require a signed-in user on that path.
Cookies you never see
The edge removes every cookie named asp_…, __Host-asp_… or __Secure-asp_… before a
request reaches your service: those names belong to the auth service. Use any other names
for your own cookies; one with a reserved name would never arrive.
Your own cookies
Every portal’s address is under agent-app.eu, so every other portal is the same site as
yours. A page on another portal can set a cookie for all of agent-app.eu with script,
and browsers then send it to your service too. Name your own cookies __Host-… (with
Secure, Path=/ and no Domain): browsers accept those only from your own address. Don’t
rely on SameSite to keep other portals out.
The identity header
Every request from a signed-in user that reaches your service has x-agentspaces-identity:
a JSON object, base64url-encoded without padding. It has no signature, and needs none: the
edge is the only way into your machine, and it always removes every x-agentspaces-*
header a client sends (in any letter case, any number of copies) before it adds its own.
So you can map it straight to your app’s own login (a Frappe or Django user, say): a
request with the header was checked by the edge, and one without it never signed in. With
anonymous access on, requests without it come from visitors
without an account.
{"v": 1, "portal": "013190e5-…", "sub": "01a1c587-7d4e-…", "kind": "session",
"sid": "01a1c587-7f41-…", "exp": 1794315653, "locale": "nl",
"email": "ada@example.com", "name": "Ada Lovelace"}| Field | Meaning |
|---|---|
v | protocol version; 1. Refuse a version you don’t know. |
portal | the portal’s id. Fixed for the portal’s life. |
sub | the user: the auth service’s id for them, stable for as long as they have an account in this portal. Key your own user record on it. |
kind | session (a browser, or a bearer token of a signed-in user), oauth (an OAuth access token: MCP and API clients), service (the auth service itself, see Sign-ups and approval), developer (one of your project’s developers with an AgentSpaces API key, only at the developer MCP path). |
sid | the sign-in session, when there is one. |
scope | oauth: the granted scopes, space-separated (mcp, api); developer: the key’s, read_write or read_only. |
email | session: the user’s email address, the one their last sign-in proved: the one they typed with their password, the magic link or reset mail’s, or the one Google, Microsoft or AgentSpaces verified. An account that hasn’t signed in since 2026-11-26 has none until its next sign-in. developer: the developer’s email address. |
name | session only, when known: the name Google, Microsoft or AgentSpaces gave at the user’s last sign-in with one of them. Password and magic-link accounts have none (a later password sign-in keeps a name they had). |
client_id | oauth only: the OAuth client. |
exp | when the token behind this request expires (Unix seconds). |
locale | session only, when known: the user’s language (en, nl, de, fr, es, da, pt, sv), the one the sign-in pages last spoke to them. Speak it too; it follows a switch within five minutes. See Languages. |
What you must do:
- The header is trustworthy because the edge is your only way in. The edge removes any copy a client sends and puts in its own. Don’t expose your port any other way, and refuse requests without the header (they can only come from inside the machine, or from visitors without an account on a portal with anonymous access).
- Key users on
sub, notemail.subnever changes; the email can (a Google account renamed, a sign-in with another provider). Useemailandnameto fill in or update your user record, and expect either to be missing:namefor password and magic-link accounts, both for an account that hasn’t signed in since they came. You also get the email once at sign-up approval. - Check
kindandscopewhere it matters: your MCP endpoint should requirekind == "oauth"with scopemcp(or asession, if you allow it); the sign-up endpoint requireskind == "service"; ordinary pages should refuseservice.
Decoding it in Python:
import base64, json
def identity(headers):
raw = headers.get("x-agentspaces-identity")
if not raw:
return None
ident = json.loads(base64.urlsafe_b64decode(raw + "=" * (-len(raw) % 4)))
if ident.get("v") != 1:
raise ValueError("unknown identity version")
return identIn Node:
function identity(req) {
const raw = req.headers["x-agentspaces-identity"];
if (!raw) return null;
const ident = JSON.parse(Buffer.from(raw, "base64url").toString("utf8"));
if (ident.v !== 1) throw new Error("unknown identity version");
return ident;
}