Tell your app who is viewing
Houseguest™ signs viewers in before they reach the app. The identity header passes on who they are: every
request the edge forwards for a signed-in viewer carries Houseguest-Identity, a short-lived token signed by
Houseguest with the viewer’s email address, their name, and how their sign-in proved the address. The app can then
sign the viewer in as themselves, or as a demo account, without a second login.
It is off by default and set per hostname. Two places decide what the app receives:
| Where | What it decides |
|---|---|
| The console, the hostname’s Advanced section | Whether the edge sends the token for that hostname |
The agent’s host, HG_IDENTITY_FILE (agent 0.7.0 or later) |
Whether the agent checks the token and hands the app plain headers instead (“checked by the agent”), or passes the token to the app (“passed through”) |
The console shows which of the two the agent does for each hostname, as the agent reports it.
Whatever the setting, the edge removes every Houseguest- header a viewer sends (in any case, and with _ for
-), so a viewer can never send one of their own. While any hostname of a preview has the identity header on,
the viewer’s Houseguest sign-in page and the Before you start page say This app receives your email address
and name., and the preview’s page in the console says The app receives each viewer’s identity.
Turn it on
Section titled “Turn it on”- On Agents, open the agent that forwards the hostname, then the hostname’s Edit.
- Open Advanced and switch on Identity header. Save.
Changing it needs the Manage headers sent to apps permission, which Owner and Admin hold. Everyone who can
see the agent sees the setting. The activity log records each change and who made it. The API sets it too:
POST /api/v1/agents/{agent_id}/hostnames/{hostname}/identity-header with {"enabled": true}
(API reference).
Checked by the agent: plain headers, no code
Section titled “Checked by the agent: plain headers, no code”Many apps already sign people in from a header set by a trusted proxy. For those, let the agent check the token:
list the hostname in the agent’s HG_IDENTITY_FILE, with the header names the app expects. The syntax is on
Install an agent § Identity check. For a listed hostname the agent:
- verifies each token (signature, hostname, expiry, issuer) and refuses a request without a valid one (
403); - removes the token and any copy of the two headers the viewer sent;
- sends the app the viewer’s email address and name in the two headers you named (
Houseguest-EmailandHouseguest-Nameunless you name others), and inHouseguest-Amrhow the sign-in proved the address, such aslink code(agent 0.8.1 or later; see How the address was proved); - with
provedon the hostname’s line, refuses (403) a viewer who signed in with an invite link alone.
The hostname’s Advanced section then reads, for example, Checked by the agent: the app receives X-Remote-User and X-Remote-Name (set on the agent, as the agent reports it). Turn the identity header on for every hostname the agent checks: with it off, the agent has no token to check and viewers get an error, and the console says so.
Recipes
Section titled “Recipes”The examples use X-Remote-User for the email address and X-Remote-Name for the name. Django, Grafana and
Jenkins match the address to an account that may already exist, an administrator’s included, so their line ends
with proved (agent 0.8.1 or later): only viewers whose sign-in proved the address reach the app.
# HG_IDENTITY_FILE on the agent's hoststaging.example.com email=X-Remote-User name=X-Remote-Name provedDjango. The remote-user middleware with the header name, and the backend that creates an account on first visit:
from django.contrib.auth.middleware import PersistentRemoteUserMiddleware
class HouseguestUserMiddleware(PersistentRemoteUserMiddleware): header = "HTTP_X_REMOTE_USER" # X-Remote-User
# settings.pyMIDDLEWARE = [ # ... after django.contrib.auth.middleware.AuthenticationMiddleware: "myproject.middleware.HouseguestUserMiddleware",]AUTHENTICATION_BACKENDS = ["django.contrib.auth.backends.RemoteUserBackend"]Grafana. Auth proxy, with the email as the login and the name as the display name:
[auth.proxy]enabled = trueheader_name = X-Remote-Userheader_property = emailauto_sign_up = trueheaders = Name:X-Remote-NameJenkins. With the Reverse Proxy Auth plugin: Manage Jenkins › Security › Security Realm › HTTP Header by
reverse proxy, Header User Name X-Remote-User.
Express. Read the headers the agent set. Houseguest-Amr lists how the sign-in proved the address:
anything but link alone proved it.
app.use((req, res, next) => { const amr = (req.get('houseguest-amr') || '').split(' ').filter(Boolean); req.viewer = { email: req.get('x-remote-user'), name: req.get('x-remote-name') || '', proved: amr.some(m => m !== 'link') }; if (!req.viewer.email) return res.status(403).send('No viewer'); next();});// Only a proved viewer may become an existing account: if (!req.viewer.proved) treat them as a guest.Passed through: check the token in the app
Section titled “Passed through: check the token in the app”For a hostname the agent does not check (and with agents older than 0.7.0), the app receives the token itself in
Houseguest-Identity and checks it. The hostname’s Advanced section reads Passed through: the app receives
the signed token and must check it (as the agent reports it), and shows the Workspace id for apps that check the token (wks_…, with
Copy; also in Settings).
A token proves which Houseguest workspace and which viewer, but only when the app checks all of it: the signature,
iss, aud (its own hostname), exp, and wid (its workspace id). aud alone is not enough: another
Houseguest workspace can preview a hostname with the same name and get tokens whose aud matches yours. Pinning
wid refuses those. The agent’s own check needs no wid, since only your workspace’s tunnel reaches your agent.
The token
Section titled “The token”A JWT (RFC 7519) signed with Ed25519: header {"alg": "EdDSA", "kid": "<key id>", "typ": "JWT"}.
| Claim | Value |
|---|---|
iss |
The console’s address: https://console.houseguest.dev on the hosted service, https://console.<domain> on a self-hosted edge |
aud |
The hostname the request is for, such as staging.example.com. For a Houseguest address (*.houseguest.page), the app’s own hostname behind it, which is also the Host the app receives |
wid |
The workspace’s id for apps: wks_ and 24 characters, shown in the console. It never changes and is never reused. Require it |
sub |
A stable id for this person in this workspace (hg_ and 22 characters). The same on every preview and hostname of the workspace, different in another workspace; it reveals neither the address nor the workspace |
email |
The viewer’s email address, lower case, as they signed in |
name |
Their name, when the address belongs to a member of the workspace and their sign-in proved it (amr has more than link); absent otherwise |
amr |
How the sign-in proved the address, a list: link, code, sso, social. See How the address was proved. Tokens from before 2026-11 have none |
preview |
The preview’s id, as in the console’s address bar and the API |
workspace |
The workspace’s short name, for display only: it changes if the workspace is renamed. Check wid, and use sub to recognize people |
iat, exp |
Issued at, and 5 minutes later. The edge reuses a token for up to 4 minutes |
Check the signature with the key the header’s kid names, then iss, aud (your own hostname), wid (your
workspace id) and exp (allow 30 seconds for clock differences).
How the address was proved
Section titled “How the address was proved”amr (and, from an agent that checks the token, Houseguest-Amr, space-separated) lists the ways the viewer’s
sign-in went:
| Value | The sign-in |
|---|---|
link |
An invite link. It proves only that someone holds the link: whoever created the invite holds it too, and can make one for any address |
code |
A code sent to the address: the invite’s email code, a standing-access sign-in code, or the code after Google or Microsoft |
sso |
The workspace’s own single sign-on (OIDC or SAML) |
social |
Google or Microsoft |
An invite link with the email code gives ["link", "code"]; Google followed by the email code gives
["social", "code"]. The address is proved when the list holds anything but link. A viewer with ["link"]
alone is whoever opened a link that someone with the right to invite viewers made: treat them as a guest, and
never sign them in to an account that already exists for that address. The token leaves out name for them, so a
member’s name never vouches for an address nobody proved.
The claim was added in 2026-11; a token without it comes from an older console and proves nothing either.
A token stays valid for its 5 minutes even if the viewer is revoked or the preview ends in the meantime: anyone holding a delivered token could replay it to the app directly for up to about 330 seconds (5 minutes and the leeway). Houseguest stops sending tokens for that viewer at once, so check the token on every request, or at least again before trusting a session the app made from it; do not turn one token into a long-lived session.
The keys
Section titled “The keys”The public keys are a JWKS (RFC 7517, kty OKP, crv Ed25519) on the console, the issuer every token
names in iss:
https://console.houseguest.dev/.well-known/houseguest/jwks.json- self-hosted:
https://console.<domain>/.well-known/houseguest/jwks.json
Fetch the keys from the console, directly, and never through the proxy that delivers the token. Whatever carries the token to the app must not also be where the app gets the key that checks it: a proxy in that position could hand over a key of its own and sign any identity it likes. The agent (0.7.1 or later) fetches the keys from the console for the same reason.
The JWKS answers with Cache-Control: max-age=600. Keys rotate: a new key signs at once and the old one stays in
the JWKS for 7 days. A key that leaked is removed from the JWKS within about 30 seconds, but copies cached by the
agent and by apps keep it for up to 10 minutes more, longer while they cannot fetch the JWKS again. Cache the
JWKS, and fetch it again when a token names a key you do not have (at most every 30 seconds), as the verifiers
below do. An app without internet access can have the agent serve the keys it holds (HG_JWKS_LISTEN, on the
agent install page).
Single-file verifiers
Section titled “Single-file verifiers”Each checks the signature against the JWKS, then iss, aud, wid and exp with 30 seconds’ leeway, and
gives the viewer’s email and name. The JWKS is cached for 10 minutes and fetched again for a key it lacks, at most
once every 30 seconds however many requests arrive. A fetch gives up after 5 seconds and never holds up requests
whose key is already cached; a JWKS that cannot be refreshed stays in use for up to an hour. All four settings are
required: audience is the hostname the app is shared on, workspace the console’s Workspace id for apps that
check the token.
Node (Express middleware)
Section titled “Node (Express middleware)”Node 18 or later, no dependencies: node:crypto and fetch.
// houseguest-identity.mjs: verifies the Houseguest-Identity header (Node 18+, no dependencies).// Usage: app.use(houseguestIdentity({ jwks: 'https://console.houseguest.dev/.well-known/houseguest/jwks.json',// issuer: 'https://console.houseguest.dev', audience: 'staging.example.com',// workspace: 'wks_…' /* the console's "Workspace id for apps that check the token" */ })); then req.viewer.emailimport { createPublicKey, verify } from 'node:crypto';
export function houseguestIdentity({ jwks, issuer, audience, workspace, leeway = 30 }) { if (!jwks || !issuer || !audience || !workspace) throw new Error('houseguestIdentity: jwks, issuer, audience and workspace are required'); let keys = new Map(), fetchedAt = 0, triedAt = 0, pending = null; // One fetch at a time, at most every 30 seconds whatever the traffic, each abandoned after 5 seconds. function refresh() { if (!pending) { triedAt = Date.now(); pending = (async () => { const res = await fetch(jwks, { signal: AbortSignal.timeout(5000) }); if (!res.ok) throw new Error(`JWKS: HTTP ${res.status}`); const doc = await res.json(); keys = new Map((doc.keys || []) .filter(k => k.kty === 'OKP' && k.crv === 'Ed25519' && typeof k.kid === 'string') .map(k => [k.kid, createPublicKey({ key: { kty: 'OKP', crv: 'Ed25519', x: k.x }, format: 'jwk' })])); fetchedAt = Date.now(); })().catch(() => {}).finally(() => { pending = null; }); // a failed fetch keeps the old keys } return pending; } async function key(kid) { const due = Date.now() - triedAt >= 30_000; // Refresh a set older than 10 minutes in the background; wait (at most 5 s) only for a key we lack (a rotation). if (Date.now() - fetchedAt > 600_000 && due) refresh(); if (!keys.has(kid) && (pending || due)) await refresh(); if (Date.now() - fetchedAt > 3_600_000) return undefined; // not refreshed for an hour: refuse return keys.get(kid); } const part = s => { const v = JSON.parse(Buffer.from(s, 'base64url').toString('utf8')); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('not a token'); return v; };
async function check(token) { const parts = String(token || '').split('.'); if (parts.length !== 3) throw new Error('no token'); const [h, p, s] = parts; let header, claims; try { header = part(h); claims = part(p); } catch { throw new Error('not a token'); } if (header.alg !== 'EdDSA') throw new Error('not EdDSA'); const k = await key(header.kid); if (!k || !verify(null, Buffer.from(`${h}.${p}`), k, Buffer.from(s, 'base64url'))) throw new Error('bad signature'); const now = Math.floor(Date.now() / 1000); if (claims.iss !== issuer) throw new Error('wrong issuer'); if (claims.aud !== audience) throw new Error('wrong audience'); if (claims.wid !== workspace) throw new Error('wrong workspace'); if (typeof claims.exp !== 'number' || now > claims.exp + leeway) throw new Error('expired'); const amr = Array.isArray(claims.amr) ? claims.amr.filter(m => typeof m === 'string') : []; return { email: claims.email, name: claims.name || '', sub: claims.sub, preview: claims.preview, workspace: claims.workspace, amr, proved: amr.some(m => m !== 'link') }; // proved: not an invite link alone }
const middleware = async (req, res, next) => { let viewer; try { viewer = await check(req.get('houseguest-identity')); } catch (e) { return res.status(403).send('Houseguest identity: ' + e.message); } req.viewer = viewer; next(); }; middleware.check = check; // for scripts and tests return middleware;}import express from 'express';import { houseguestIdentity } from './houseguest-identity.mjs';const app = express();app.use(houseguestIdentity({ jwks: 'https://console.houseguest.dev/.well-known/houseguest/jwks.json', issuer: 'https://console.houseguest.dev', audience: 'staging.example.com', workspace: 'wks_…' }));app.get('/', (req, res) => res.send(`Hello ${req.viewer.name || req.viewer.email}`));// Match req.viewer to an existing account only when req.viewer.proved.Python
Section titled “Python”One file. It needs the cryptography package for Ed25519
(pip install cryptography); the rest is the standard library.
"""houseguest_identity.py: verifies the Houseguest-Identity header.
Needs the `cryptography` package (pip install cryptography); everything else is the standard library.
v = Verifier(jwks="https://console.houseguest.dev/.well-known/houseguest/jwks.json", issuer="https://console.houseguest.dev", audience="staging.example.com", workspace="wks_…") # the console's "Workspace id for apps that check the token" viewer = v.check(request.headers.get("Houseguest-Identity")) # raises InvalidIdentity viewer["email"], viewer["name"] viewer["proved"] # False for an invite link alone: never match it to an existing account"""import base64, json, threading, time, urllib.requestfrom cryptography.exceptions import InvalidSignaturefrom cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
class InvalidIdentity(Exception): pass
def _b64(s): return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
def _obj(s): v = json.loads(_b64(s)) if not isinstance(v, dict): raise ValueError("not a JSON object") return v
class Verifier: def __init__(self, jwks, issuer, audience, workspace, leeway=30): if not (jwks and issuer and audience and workspace): raise ValueError("jwks, issuer, audience and workspace are required") self.jwks, self.issuer, self.audience, self.workspace, self.leeway = jwks, issuer, audience, workspace, leeway self._keys, self._at, self._tried, self._fetching = {}, 0.0, 0.0, None self._lock = threading.Lock() # guards the fields above; never held during a fetch
def _fetch(self, done): try: with urllib.request.urlopen(self.jwks, timeout=5) as r: doc = json.loads(r.read(65536)) keys = {k["kid"]: Ed25519PublicKey.from_public_bytes(_b64(k["x"])) for k in doc["keys"] if k.get("kty") == "OKP" and k.get("crv") == "Ed25519"} with self._lock: self._keys, self._at = keys, time.time() except Exception: pass # a failed fetch keeps the old keys finally: with self._lock: self._fetching = None done.set()
def _key(self, kid): # One fetch at a time, at most every 30 s whatever the traffic. A set older than 10 minutes # is refreshed while the old one stays in use; only a key we lack (a rotation) waits for it. with self._lock: now = time.time() if (now - self._at > 600 or kid not in self._keys) and not self._fetching and now - self._tried >= 30: self._tried, self._fetching, fetch = now, threading.Event(), True else: fetch = False done = self._fetching wait = done is not None and kid not in self._keys if fetch: if wait: self._fetch(done) else: threading.Thread(target=self._fetch, args=(done,), daemon=True).start() elif wait: done.wait(6) with self._lock: if time.time() - self._at > 3600: # not refreshed for an hour: refuse return None return self._keys.get(kid)
def check(self, token): try: h, p, s = (token or "").split(".") header, claims = _obj(h), _obj(p) except ValueError: raise InvalidIdentity("no token") if header.get("alg") != "EdDSA" or not isinstance(header.get("kid"), str): raise InvalidIdentity("not EdDSA") key = self._key(header["kid"]) try: if key is None: raise InvalidSignature() key.verify(_b64(s), f"{h}.{p}".encode()) except (InvalidSignature, ValueError): raise InvalidIdentity("bad signature") if claims.get("iss") != self.issuer: raise InvalidIdentity("wrong issuer") if claims.get("aud") != self.audience: raise InvalidIdentity("wrong audience") if claims.get("wid") != self.workspace: raise InvalidIdentity("wrong workspace") exp = claims.get("exp") if not isinstance(exp, int) or isinstance(exp, bool) or time.time() > exp + self.leeway: raise InvalidIdentity("expired") amr = claims.get("amr") amr = [m for m in amr if isinstance(m, str)] if isinstance(amr, list) else [] return {"email": claims.get("email"), "name": claims.get("name", ""), "sub": claims.get("sub"), "preview": claims.get("preview"), "workspace": claims.get("workspace"), "amr": amr, "proved": any(m != "link" for m in amr)} # proved: not an invite link aloneThe standard library only (crypto/ed25519).
// Package hgidentity verifies the Houseguest-Identity header with the standard library only.//// v := &hgidentity.Verifier{JWKS: "https://console.houseguest.dev/.well-known/houseguest/jwks.json",// Issuer: "https://console.houseguest.dev", Audience: "staging.example.com",// Workspace: "wks_…"} // the console's "Workspace id for apps that check the token"// viewer, err := v.Check(r.Header.Get("Houseguest-Identity")) // viewer.Email, viewer.Name// viewer.Proved // false for an invite link alone: never match it to an existing accountpackage hgidentity
import ( "crypto/ed25519" "encoding/base64" "encoding/json" "errors" "fmt" "io" "net/http" "strings" "sync" "time")
type Viewer struct { Email, Name, Sub, Preview, Workspace string AMR []string // how the sign-in proved the address: link, code, sso, social Proved bool // AMR holds more than an invite link}
type Verifier struct { JWKS, Issuer, Audience, Workspace string // all required mu sync.Mutex keys map[string]ed25519.PublicKey at, tried time.Time fetching chan struct{} // closed when the fetch in flight ends}
var client = &http.Client{Timeout: 5 * time.Second}
// key gives the key named kid. One fetch at a time, at most every 30 s whatever the traffic,// never under the lock. A set older than 10 minutes is refreshed while the old one stays in// use; only a key it lacks (a rotation) waits for the fetch, at most its 5 s.func (v *Verifier) key(kid string) ed25519.PublicKey { v.mu.Lock() now := time.Now() if (now.Sub(v.at) > 10*time.Minute || v.keys[kid] == nil) && v.fetching == nil && now.Sub(v.tried) >= 30*time.Second { v.tried, v.fetching = now, make(chan struct{}) go v.fetch(v.fetching) } var wait chan struct{} if v.keys[kid] == nil { wait = v.fetching } v.mu.Unlock() if wait != nil { select { case <-wait: case <-time.After(6 * time.Second): } } v.mu.Lock() defer v.mu.Unlock() if time.Since(v.at) > time.Hour { // not refreshed for an hour: refuse return nil } return v.keys[kid]}
func (v *Verifier) fetch(done chan struct{}) { keys, err := fetchJWKS(v.JWKS) v.mu.Lock() if err == nil { // a failed fetch keeps the old keys v.keys, v.at = keys, time.Now() } v.fetching = nil v.mu.Unlock() close(done)}
func fetchJWKS(url string) (map[string]ed25519.PublicKey, error) { resp, err := client.Get(url) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("JWKS: HTTP %d", resp.StatusCode) } var doc struct { Keys []struct{ Kty, Crv, Kid, X string } } if err := json.NewDecoder(io.LimitReader(resp.Body, 64<<10)).Decode(&doc); err != nil { return nil, err } keys := map[string]ed25519.PublicKey{} for _, k := range doc.Keys { if x, err := base64.RawURLEncoding.DecodeString(k.X); err == nil && k.Kty == "OKP" && k.Crv == "Ed25519" && len(x) == ed25519.PublicKeySize { keys[k.Kid] = x } } return keys, nil}
func (v *Verifier) Check(token string) (*Viewer, error) { if v.JWKS == "" || v.Issuer == "" || v.Audience == "" || v.Workspace == "" { return nil, errors.New("hgidentity: JWKS, Issuer, Audience and Workspace are required") } parts := strings.Split(token, ".") if len(parts) != 3 { return nil, errors.New("no token") } var h struct{ Alg, Kid string } var c struct { Iss, Aud, Sub, Wid, Email, Name, Preview, Workspace string Exp int64 AMR []string `json:"amr"` } hb, err1 := base64.RawURLEncoding.DecodeString(parts[0]) pb, err2 := base64.RawURLEncoding.DecodeString(parts[1]) sig, err3 := base64.RawURLEncoding.DecodeString(parts[2]) if err1 != nil || err2 != nil || err3 != nil || json.Unmarshal(hb, &h) != nil || json.Unmarshal(pb, &c) != nil || h.Alg != "EdDSA" { return nil, errors.New("not a Houseguest token") } k := v.key(h.Kid) switch { case k == nil || !ed25519.Verify(k, []byte(parts[0]+"."+parts[1]), sig): return nil, errors.New("bad signature") case c.Iss != v.Issuer: return nil, errors.New("wrong issuer") case c.Aud != v.Audience: return nil, errors.New("wrong audience") case c.Wid != v.Workspace: return nil, errors.New("wrong workspace") case time.Now().Unix() > c.Exp+30: // 30 s leeway return nil, errors.New("expired") } proved := false for _, m := range c.AMR { proved = proved || m != "link" } return &Viewer{Email: c.Email, Name: c.Name, Sub: c.Sub, Preview: c.Preview, Workspace: c.Workspace, AMR: c.AMR, Proved: proved}, nil}Map viewers to accounts
Section titled “Map viewers to accounts”The token says who the viewer is; the app decides what they may do. Two common choices:
- Create the account on first visit. Look the viewer up by
sub(or byemail), and create an account when there is none, with the role a guest should have. The Django and Grafana recipes above do this. Match a viewer to an account that already exists only when the address was proved (amrholds more thanlink; the agent’sproveddoes this for you): otherwise someone with the right to invite viewers can arrive as any account by inviting its address. - Map everyone to a demo account. Sign every viewer in as one shared account with sample data, and keep
emailfor the app’s own audit trail. Nobody needs an account of their own.
Either way, treat the identity as “this person was invited to this preview”, not as membership of your
organization: anyone a sharer invites can receive a token. And with amr of link alone, treat it as “someone
holding an invite link for this address”, not as that person.
© 2026 Houseguest Technologies LLC. Houseguest™ is its trademark.7723 Tylers Place Blvd., Box #119, West Chester, OH 45069