# Agent proof of possession lab: why a copied token is not enough

> A local issuer and resource server: a bearer token alone was refused, a signed proof was accepted once, and replay, wrong-key and forged proofs failed.

- URL: https://iamops.dev/agent-proof-of-possession-lab/
- Language: en
- Author: Argo
- Published: 2026-12-04
- Category: Labs
- Depth: Practitioner
- Audience: Engineers and operators
- Time: 12 min
- Topics: proof of possession, tokens, agents, Labs

## TL;DR

- The [bearer token alone is refused](https://iamops.dev/agent-proof-of-possession-lab/#step-5-a-bearer-token-alone-is-refused) with proof_required, so a copied token is not enough on its own.
- The [signed proof](https://iamops.dev/agent-proof-of-possession-lab/#step-6-the-agent-signs-the-request-and-the-call-succeeds) is accepted, and the [same proof](https://iamops.dev/agent-proof-of-possession-lab/#step-7-the-same-proof-cannot-be-used-twice) is refused the second time.
- A [proof from another key](https://iamops.dev/agent-proof-of-possession-lab/#step-8-a-proof-from-another-key-is-refused) and a [forged proof](https://iamops.dev/agent-proof-of-possession-lab/#step-9-a-proof-that-swaps-in-the-agents-public-key-fails-the-signature) fail on the key check and the signature check.
- The [legacy endpoint](https://iamops.dev/agent-proof-of-possession-lab/#step-10-the-old-endpoint-still-takes-the-bearer-token-alone) still accepts the bearer token alone. That is the gap a stolen token would use.
- This is a [generic demo](https://iamops.dev/agent-proof-of-possession-lab/#what-this-does-not-cover) built on the ideas in Request for Comments (RFC) 9449 (DPoP). The agent-specific spec is not published yet, so those parts are marked to watch.

**Audience: Practitioners.** Developers and identity engineers who want to see why a bearer token needs a second factor on each call. Skip the setup if you only want the result.

A bearer token works for whoever holds it. If an agent's token is copied, the copy works too, unless the resource server also checks something the copy does not have. This lab binds the token to a key and makes the resource server check a signed proof on every call.

The lab uses one Python file with the standard library, plus openssl, curl and jq. The issuer binds the token to the agent's public key. The resource server checks the token, then the proof. The proof is signed with the agent's private key and covers the method, the path and a hash of the token.

This is a generic demo. It follows the idea of proof of possession from [<abbr title="Request for Comments">RFC</abbr> 9449](https://datatracker.ietf.org/doc/html/rfc9449), and it is not an implementation of the agent-specific spec. That spec is not published yet, so agent-specific spec details are marked to watch and are not claimed here.

## Setup

You need Python 3, curl, jq, openssl and tr. The issuer listens on 127.0.0.1 port 4901 and the resource server on port 4902. Nothing needs an account, and nothing leaves the computer after the download.

The service is one file, [pop_lab.py](https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py), and the helper functions are in [agent_proof.sh](https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh).

## Step 1: Download the service and make two keys

```bash
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pem
```

The private keys stay in files that only you can read. The cleanup step deletes them.

## Step 2: Start both services

```bash
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out
```

![Terminal output: the two start commands in the background, then the cat of both output files showing the issuer on 4901 and the resource server on 4902 listening](https://iamops.dev/media/agent-proof-of-possession-lab/02-start.webp)

*Step 2. Both services listen on 127.0.0.1.*

## Step 3: Check the health endpoints

```bash
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .
```

![Terminal output: two JSON health lines, one for the issuer and one for the resource server, both ok true](https://iamops.dev/media/agent-proof-of-possession-lab/03-health.webp)

*Step 3. Both services answer.*

## Step 4: Get a token bound to the agent's key

```bash
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"'
```

![Terminal output: the decoded token claims, sub demo-agent, scope calendar.read, and a cnf.jkt thumbprint of the agent's key](https://iamops.dev/media/agent-proof-of-possession-lab/04-claims.webp)

*Step 4. The token carries the key thumbprint in cnf.jkt.*

The `cnf.jkt` claim is the thumbprint of the agent's public key. That is what ties the token to the key.

## Step 5: A bearer token alone is refused

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 401, error proof_required, with the detail that the endpoint needs an Agent-Proof header signed with the bound key](https://iamops.dev/media/agent-proof-of-possession-lab/05-bearer-only.webp)

*Step 5. The token alone is refused.*

## Step 6: The agent signs the request and the call succeeds

```bash
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 200 with ok true, the endpoint, the agent demo-agent, scope calendar.read, and proof checked](https://iamops.dev/media/agent-proof-of-possession-lab/06-signed.webp)

*Step 6. The signed proof is accepted.*

The proof covers the method, the path, a timestamp, a one-time id and a hash of the token. A proof for one request does not work for another path or token.

## Step 7: The same proof cannot be used twice

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 401, error replay, the proof was already used once](https://iamops.dev/media/agent-proof-of-possession-lab/07-replay.webp)

*Step 7. The repeat is refused as a replay.*

## Step 8: A proof from another key is refused

```bash
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 401, error key_mismatch, the proof key is not the key this token is bound to](https://iamops.dev/media/agent-proof-of-possession-lab/08-other-key.webp)

*Step 8. A key the token is not bound to is refused.*

## Step 9: A proof that swaps in the agent's public key fails the signature

```bash
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 401, error bad_signature, the proof signature does not verify](https://iamops.dev/media/agent-proof-of-possession-lab/09-forged-pub.webp)

*Step 9. Putting the right public key next to a wrong signature fails.*

The attacker can copy the public key from the header, but cannot sign with the private key. The signature check is what stops that.

## Step 10: The old endpoint still takes the bearer token alone

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

![Terminal output: HTTP 200 with ok true on the legacy calendar endpoint, and proof not required](https://iamops.dev/media/agent-proof-of-possession-lab/10-legacy.webp)

*Step 10. The legacy endpoint accepts the stolen-token case.*

This is the lesson of the lab. Any endpoint that accepts the bearer token without the proof lets a copied token work. The fix is to require the proof everywhere the token is accepted.

## Step 11: Read what the resource server logged

```bash
cat run/resource.log
```

![Terminal output: the resource server log lines, one per request, with the status and the reason](https://iamops.dev/media/agent-proof-of-possession-lab/11-log.webp)

*Step 11. Each refusal has a reason in the log.*

## Step 12: Clean up

```bash
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left"
```

![Terminal output: the cleanup check, no listener on 4901 or 4902 and no pop_lab.py process left](https://iamops.dev/media/agent-proof-of-possession-lab/12-cleanup.webp)

*Step 12. The services and the keys are gone.*

## What this does not cover

- The proof format is this lab's own, not the agent-specific spec format. agent-specific spec is to watch until its spec is published.
- The issuer and the resource server share one local trust setup and one process each. A real deployment needs key rotation, a key store and proper token lifetimes.
- The legacy endpoint is there on purpose, to show the gap.

## Repeat this lab

You need Python 3 (no extra packages), curl, jq, openssl and tr. Everything runs on your own computer on ports 4901 and 4902, with no account and no internet access after the download. Plan for about 15 minutes. This is a generic proof-of-possession demo, not the AAuth spec, which is not published yet.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

**Set your variables once** `env.sh` (bash)

```bash
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902
```

### Step 1: Download the service and make two keys

**Goal.** Create a work folder, download the service and the helper functions, and make an issuer key and an agent key that only you can read.

**Prerequisites**

- Python 3, curl, jq, openssl and tr

`setup.sh` (bash)

```bash
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pem
```

**Expected output**

```text
(no output)
```

### Step 2: Start the issuer and the resource server

**Goal.** Start both services on 127.0.0.1. The issuer signs the tokens, and the resource server checks the token and the proof on every call.

**Prerequisites**

- The setup step has completed
- Ports 4901 and 4902 are free

`start.sh` (bash)

```bash
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out
```

**Expected output**

```text
issuer listening on 127.0.0.1:4901
resource listening on 127.0.0.1:4902
```

### Step 3: Check both health endpoints

**Goal.** Confirm both services answer before you send any request.

**Prerequisites**

- The start step has completed

`health.sh` (bash)

```bash
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .
```

**Expected output**

```text
{"role":"issuer","ok":true}
{"role":"resource","ok":true}
```

### Step 4: Get a token bound to the agent's key

**Goal.** The issuer returns a token for the agent. The token carries a confirmation claim, cnf.jkt, that is the thumbprint of the agent's public key.

**Prerequisites**

- The health step has completed

`token.sh` (bash)

```bash
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"'
```

**Expected output**

```text
sub: demo-agent
scope: calendar.read
cnf.jkt: _AjEqWefsVfSdbOwV9dDsLuYAJia9ZPF9PrLfV2N37A
```

### Step 5: A bearer token alone is refused

**Goal.** Send the token with no proof. The resource server refuses it, because a copied bearer token is not enough.

**Prerequisites**

- The token step has completed

`bearer-only.sh` (bash)

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 401
error: proof_required
detail: this endpoint needs an Agent-Proof header signed with the key the token is bound to
```

### Step 6: The agent signs the request and the call succeeds

**Goal.** Sign the method, the path and the token hash with the agent's key, and send the proof in a header next to the token.

**Prerequisites**

- The token step has completed

`proof.sh` (bash)

```bash
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 200
ok: true
endpoint: /v1/calendar
agent: demo-agent
scope: calendar.read
proof: checked
```

### Step 7: The same proof cannot be used twice

**Goal.** Send the proof from the previous step a second time. Each proof carries a one-time id, and the resource server refuses the repeat.

**Prerequisites**

- The proof step has completed

`replay.sh` (bash)

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 401
error: replay
detail: this proof was already used once
```

### Step 8: A proof from another key is refused

**Goal.** Make a second key, sign a proof with it, and send it with the agent's token. The token is bound to the first key, so the call fails.

**Prerequisites**

- The token step has completed

`other-key.sh` (bash)

```bash
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 401
error: key_mismatch
detail: the proof key is not the key this token is bound to
```

### Step 9: A proof that swaps in the agent's public key fails the signature

**Goal.** Sign with the second key, but put the agent's public key in the header. The key matches the token, yet the signature does not verify.

**Prerequisites**

- The other-key step has completed

`forged-key.sh` (bash)

```bash
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 401
error: bad_signature
detail: the proof signature does not verify
```

### Step 10: The old endpoint still takes the bearer token alone

**Goal.** Call the legacy endpoint with only the bearer token. It accepts it, which is the gap a stolen token would use.

**Prerequisites**

- The token step has completed

`legacy.sh` (bash)

```bash
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
```

**Expected output**

```text
HTTP 200
ok: true
endpoint: /v1/legacy/calendar
agent: demo-agent
scope: calendar.read
proof: not required
```

### Step 11: Clean up

**Goal.** Stop both services, delete the keys and the service files, remove the work folder, and check that nothing listens on the two ports.

**Prerequisites**

- The earlier steps have completed

`cleanup.sh` (bash)

```bash
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left"
```

**Expected output**

```text
no listener on 4901 or 4902
no pop_lab.py process left
```


## Sources

- [RFC 9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP)](https://datatracker.ietf.org/doc/html/rfc9449)

Discuss: [X](https://x.com/iamopsdev) | [LinkedIn](https://www.linkedin.com/company/iamops-dev/)
