Skip to content
Your service behind a portal

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.1 is 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:

PathWho answers
/robots.txtthe edge (Disallow: /), or the portal’s bucket when it has one
your developer MCP path, if onyour 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-configurationauth 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"}
FieldMeaning
vprotocol version; 1. Refuse a version you don’t know.
portalthe portal’s id. Fixed for the portal’s life.
subthe 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.
kindsession (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).
sidthe sign-in session, when there is one.
scopeoauth: the granted scopes, space-separated (mcp, api); developer: the key’s, read_write or read_only.
emailsession: 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.
namesession 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_idoauth only: the OAuth client.
expwhen the token behind this request expires (Unix seconds).
localesession 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, not email. sub never changes; the email can (a Google account renamed, a sign-in with another provider). Use email and name to fill in or update your user record, and expect either to be missing: name for 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 kind and scope where it matters: your MCP endpoint should require kind == "oauth" with scope mcp (or a session, if you allow it); the sign-up endpoint requires kind == "service"; ordinary pages should refuse service.

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 ident

In 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;
}
Last updated on