This directory showcases how to build, validate, and verify did:wba identities with AgentConnect. All scripts operate locally—no HTTP services are required—making them ideal for learning or offline testing.
create_did_document.py: Generates a DID document and secp256k1 key pair.validate_did_document.py: Confirms the generated document matches DID-WBA requirements.authenticate_and_verify.py: Produces a DID authentication header, verifies it, and validates the issued bearer token using demo credentials.
http_server.py: FastAPI HTTP server with DID WBA authentication middleware.http_client.py: HTTP client demonstrating the complete authentication flow.
generated/: Output directory for DID documents and key files created by the examples.
Install AgentConnect from PyPI or work from a local checkout:
pip install anp
# or
uv venv .venv
uv pip install --python .venv/bin/python --editable .The end-to-end demo relies on bundled material:
docs/did_public/public-did-doc.jsondocs/did_public/public-private-key.pemdocs/jwt_rs256/RS256-private.pemdocs/jwt_rs256/RS256-public.pem
uv run --python .venv/bin/python python examples/python/did_wba_examples/create_did_document.pyExpected output:
DID document saved to .../generated/did.json
Registered verification method key-1 → private key: key-1_private.pem public key: key-1_public.pem
Generated DID identifier: did:wba:demo.agent-network:agents:demo
Generated files:
generated/did.jsongenerated/key-1_private.pemgenerated/key-1_public.pem
uv run --python .venv/bin/python python examples/python/did_wba_examples/validate_did_document.pyThe script checks:
- Identifier format (
did:wba:prefix) - Required JSON-LD contexts
- Verification method wiring and JWK integrity
- Authentication entry referencing
key-1 - Optional HTTPS service endpoint
Expected output:
DID document validation succeeded.
uv run --python .venv/bin/python python examples/python/did_wba_examples/authenticate_and_verify.pyFlow overview:
DIDWbaAuthHeadersigns a DID header with the public demo credentials.DidWbaVerifierresolves the local DID document, verifies the signature, and issues a bearer token (RS256).- The bearer token is validated to confirm the
did:wbasubject.
Expected output:
DID header verified. Issued bearer token.
Bearer token verified. Associated DID: did:wba:didhost.cc:public
This example demonstrates a complete client-server authentication flow using actual HTTP requests.
uv run python examples/python/did_wba_examples/http_server.pyThe server starts on http://localhost:8080 with:
/health- Health check (no auth required)/api/protected- Protected endpoint (requires DID auth)/api/user-info- User info endpoint (requires DID auth)
uv run python examples/python/did_wba_examples/http_client.pyExpected output:
============================================================
Step 1: Access health endpoint (no authentication required)
============================================================
Status: 200
Response: {'status': 'healthy', 'service': 'did-wba-http-server'}
============================================================
Step 2: Access protected endpoint with DID authentication
============================================================
Auth header type: DID WBA
Authorization: DID-WBA did="did:wba:didhost.cc:public", nonce="...", timestamp=...
Status: 200
Response: {'message': 'Authentication successful!', 'did': 'did:wba:didhost.cc:public', 'token_type': 'bearer'}
Received Bearer token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
============================================================
Step 3: Access protected endpoint with cached Bearer token
============================================================
Auth header type: Bearer
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Status: 200
Response: {'message': 'Authentication successful!', 'did': 'did:wba:didhost.cc:public', 'token_type': None}
============================================================
Step 4: Access user-info endpoint with Bearer token
============================================================
Status: 200
Response: {'did': 'did:wba:didhost.cc:public', 'authenticated': True, ...}
============================================================
Demo completed successfully!
============================================================
- First Request (DID Auth): Client sends DID WBA authentication header
- Server Verification: Server verifies signature, issues JWT Bearer token
- Token Caching: Client caches the Bearer token for subsequent requests
- Subsequent Requests: Client uses cached Bearer token (more efficient)
- Missing files: Run
create_did_document.pybefore the other scripts, or confirm the sample files exist. - Invalid key format: Ensure private keys remain PEM-encoded; regenerate with the create script if necessary.
- DID mismatch: Re-run
validate_did_document.pyto highlight structural issues.
For a comprehensive guide on integrating DID WBA authentication into your own HTTP server (including authentication principles, full API reference, and copy-paste code snippets), see:
- Swap the sample credentials for your own DID material.
- Integrate
DIDWbaAuthHeaderinto HTTP clients to call remote services that expect DID WBA headers. - Pair the verifier with actual DID resolution logic once your documents are hosted publicly.