stackwell.tech
Protocols / Identity & Token Protocol

Identity & Token Protocol

The implementation-independent contract. Generated from the canonical spec protocols/specs/machine-identity.md as of 2026-11-21 (84a386d). Implemented by ChirpAuth.

Changing (decided 2026-11-15, not yet built): a machine token will be minted for one named audience, with sub and owner_sub pairwise to that relying party and no azp or client id, and Granite will key a machine by its root. The token shape, verification and Granite sections below describe today's shape until then. See docs/adr-one-machine-name.md (agent-platform--protocols#115).

This spec extends ChirpAuth to issue identities for non-human actors — agents and other machine clients — so that third parties can register and run agents that participate in the platform.

Purpose

Today ChirpAuth issues ID tokens only for humans (Authorization Code + PKCE with email-link or passkey login). This spec adds machine tokens so that every agent — platform-hosted and external alike — is identified by a single ChirpAuth machine sub (agent_…). There is no separate Drive-resource / agent_id identity space for hosted agents; they are ChirpMachines like any other.

It does not work for external agent providers — a third party who wants to run their own agent runner and participate in Pigeon, Drive, Granite, and Model Gateway as a recognized actor. They need a portable, verifiable identity that isn't bound to any single service's internal id space.

This spec adds confidential clients and the OAuth2 client_credentials grant to ChirpAuth. The same JWKS signs both human and machine tokens; consuming services use claim shape to distinguish them and decide whether to accept.

Goals

Non-Goals

Core Concepts

Term Meaning
Public client Existing: a browser-based app using Authorization Code + PKCE. No secret. Token shape includes email claim.
Confidential client New: a server-side machine actor with a client_secret. Uses client_credentials grant. Token shape includes act: "machine" and owner_sub.
Owner The human chirp-sub responsible for a confidential client. Stored on the client record. Required at registration time.
Machine token ID token issued via client_credentials. Same JWKS as human tokens; different claim shape.
Human token Existing ID token issued via Authorization Code + PKCE.

Token Shapes

Both token kinds are JWTs signed by the same rotating JWKS, with the same iss and kid. They differ in payload claims:

Human token (existing, unchanged)

{
  "iss": "https://signin.example.com",
  "sub": "sub_<random>",
  "aud": "cs_live_<client_id>",
  "exp": 1747680000,
  "iat": 1747676400,
  "nonce": "nonce_...",
  "email": "user@example.com",
  "email_verified": true
}

Machine token (new)

{
  "iss": "https://signin.example.com",
  "sub": "agent_<random>",
  "aud": "cs_live_<client_id>",
  "azp": "cs_live_<client_id>",
  "act": "machine",
  "owner_sub": "sub_<random>",
  "exp": 1747680000,
  "iat": 1747676400
}

Distinguishing rules:

Registration

The developer first authenticates as themselves (Authorization Code + PKCE). The CLI captures their human chirp-sub and uses it as owner_sub for any clients they then create.

$ chirp-auth login
Opens browser to sign in...
Signed in as alice@example.com (sub_abc...).

$ chirp-auth app create --type confidential --name "acme-summarizer"
Creating confidential client owned by sub_abc...
client_id     = cs_live_<random>
client_secret = <random_secret_shown_once_never_again>
owner_sub     = sub_abc...

The secret is hashed at rest. It cannot be retrieved later. The developer must store it themselves (env var, secrets manager, etc.). If lost, the client must be deleted and re-created.

A chirp-auth.toml for confidential clients omits redirect URIs (none are needed) and includes a type = "confidential" field. The secret is NEVER written to the toml; only the public client_id, owner_sub, name, and type are stored.

Token Issuance

POST /token accepts a new grant:

POST /token HTTP/1.1
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials

Alternative form: client_id and client_secret in the POST body. Either works.

Success response:

{
  "token_type": "Bearer",
  "expires_in": 3600,
  "id_token": "eyJ...<machine_token>"
}

No access token, no refresh token. The ID token is the bearer credential consuming services verify directly.

Failure modes (RFC 6749 compliant):

Verification

The chirp-auth-client crate exposes a single verify_chirp_id_token function that handles both token shapes. Callers indicate which kinds they accept via VerifyOptions:

pub struct VerifyOptions {
    pub require_email: bool,    // existing
    pub accept_machine: bool,   // new, default false
}

pub enum ChirpVerifiedIdentity {
    Human {
        sub: String,
        email: Option<String>,
        name: Option<String>,
    },
    Machine {
        sub: String,
        owner_sub: String,
        client_id: String,
    },
}

Default VerifyOptions accepts only human tokens. Services that want machine identities opt in. The change is additive: all current callers compile and behave as today.

Verification semantics:

Per-Service Acceptance

Service Accepts machine tokens Reason
personal-ecosystem (Social Graph) No Photo gallery is human-only. Default VerifyOptions.
Drive Yes Maps to existing DriveActor::AgentRun. Granite-grant verification already in place.
Pigeon Yes Adds Actor::AgentRun { sub, owner_sub }. Mutations require Granite grant naming sub.
Granite Yes Machine clients call /v1/grants/verify and read grant state.
Model Gateway Yes External providers spend against grants the same way hosted agents do.

Services that accept machine tokens must verify a Granite grant before performing any mutation on the owner's behalf. The token establishes identity; the grant establishes authorization. ChirpAuth never sees the grant; Granite never sees the secret.

Granite Integration

Granite grants name their subject by subject_chirp_sub — the agent's ChirpAuth machine sub (agent_…). Every agent, hosted or external, is a ChirpMachine identified by its ChirpAuth sub; there is no separate agent_id / Drive-resource identity space. (The old subject_agent_id / requester_agent_id fields were removed; a machine identity is a single chirp_sub, not one of two rails.)

The verify endpoint takes the subject as subject_chirp_sub:

POST /v1/grants/verify
{
  "grant_id": "grant_...",
  "subject_chirp_sub": "agent_..."
}

Revocation Semantics

ChirpAuth does not maintain a real-time token blacklist. When a confidential client or its owner is suspended:

This trades real-time precision for stateless verification. Consuming services do not need to call back to ChirpAuth on every request.

Operators who need immediate revocation can rotate the JWKS signing key — this invalidates ALL outstanding tokens (machine and human). It is a blunt instrument; reserve for actual key compromise.

Security Invariants

Out of Scope

Open Product Questions (not engineering)

Acceptance Criteria

The spec is implemented when: