Authenticate the viewer (Viewer VC / Stage 3)¶
Authenticate the data provider (Consent VC / Stage 1) protected the write side with a VC. This page protects the read side with a VC.
What you'll do: Present a ViewerVC to be granted read access
Prerequisites: Authenticate the data provider (Consent VC / Stage 1) finished
Keep running: the publisher started in 2.2 (
ssi-walletprofile). If you stopped it, step 1 starts it. Keep the Quickstart IPFS stopped (it shares port 8080)What you need: PC + smartphone (iw3ip-wallet)
Time required: approx. 45 min
Where this page belongs
- This is section 2.3 of Part 2 (Stage 3) (Hands-on). Section 2.3 has two pages: this one and Authenticate machines (Service VC / Stage 4 prep).
- Assumes you've completed Authenticate the data provider (Consent VC / Stage 1) (PolicyToken-gated write). This page covers Stage 3: gating read with VC presentation.
- "Phase 3" on this page is a development stage of the platform, not the learning order (Hands-on).
- Previous page: Authenticate the data provider (Consent VC / Stage 1) (2.2)
- Next page: Authenticate machines (Service VC / Stage 4 prep) (2.3)
Choosing a dataset
The example here is written for home/env/temperature, but it also
works with home/event/possible_littering, the same as Stage 0
Share detections, not raw frames (the PD in
viewer-possible-littering.json
is already registered). Choose that if you want to use the same
dataset throughout the hands-on series.
Goal¶
Where ConsentVC authorized writes (ingest), ViewerVC authorizes
reads (data retrieval). You'll present a ViewerVC with the wallet,
receive a short-lived ViewerToken, and call /platform/data to fetch
sensor rows.
Pipeline:
Mobile wallet (ViewerVC) -> OID4VP Verifier -> ViewerToken -> /platform/data
The diagram below shows how the VC you present decides which token you get and which API it opens.
flowchart LR
subgraph WAL["Mobile wallet"]
CVC["ConsentVC<br>allowed_purposes"]
VVC["ViewerVC<br>allowed_actions: read"]
end
subgraph PUB["publisher"]
VER["/verifier/response<br>verifies the presented VC"]
PT["PolicyToken<br>5 min, single use"]
VT["ViewerToken<br>60 s, reusable"]
ING["POST /platform/ingest<br>(write)"]
DATA["GET /platform/data<br>(read)"]
end
CVC -->|"present"| VER
VVC -->|"present"| VER
VER -->|"for ConsentVC"| PT
VER -->|"for ViewerVC"| VT
PT --> ING
VT --> DATA
PT -.->|"401 viewer_token_unknown"| DATA
linkStyle 6 stroke:#c0392b,color:#7b241c
/platform/data accepts only a ViewerToken. The publisher keeps PolicyTokens and ViewerTokens separately, so a PolicyToken obtained with a ConsentVC gets viewer_token_unknown (dotted line).
What this page covers¶
- Why "write VC" and "read VC" are separated
- Issuing ViewerVC via OID4VCI [1] and presenting via OID4VP [2]
- ViewerToken's 60-second TTL, and that it can be used any number of times within the TTL
- How
/platform/datareads are recorded in the audit log
Common issues¶
- ConsentVC and ViewerVC are distinct. Presenting a ConsentVC does not let you read
/platform/data /platform/dataonly accepts ViewerToken (PolicyToken is rejected)- ViewerToken TTL is 60 s. After expiry, present again
Required environment¶
- Have completed §1–§8 of Authenticate the data provider (Consent VC / Stage 1)
- Publisher running from the
mainbranch iw3ip-walletavailable on phone$HOST_IPin commands and<HOST_IP>in URLs stand for the PC's LAN IP. In each terminal you use, first runexport HOST_IP='<your PC LAN IP>'(see the Hands-on for how to find it). Replace<HOST_IP>in URLs you type into a browser or phone with the same IP
Related repositories¶
- Blockchain_IoT_Marketplace — publisher
- iw3ip-wallet — mobile SSI wallet
Shortest path¶
- Start publisher
- Write some data via ConsentVC (Stage 1 recap)
- Issue a ViewerVC and store it in the wallet
- Present ViewerVC and obtain a ViewerToken
- Read via
/platform/dataand inspect audit log
1. Start¶
cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile ssi-wallet up --build -d
curl http://$HOST_IP:8080/health
Confirm the issuer metadata advertises both ConsentVC and ViewerVC:
curl -s http://$HOST_IP:8080/.well-known/openid-credential-issuer | python3 -m json.tool | grep -E -A2 'ConsentVC|ViewerVC'
Both are registered if the output has a "ConsentVC": { line and a "ViewerVC": { line. Lines from other VCs whose names contain ViewerVC, such as PurchaseViewerVC, also appear.
2. Write data via ConsentVC (recap)¶
Follow §5–§8 of Authenticate the data provider (Consent VC / Stage 1)
to present ConsentVC, get a PolicyToken, and POST to /platform/ingest.
Those rows are what §5 will read back.
3. Issue a ViewerVC¶
Open in the PC browser:
http://<HOST_IP>:8080/issuer/offer?type=ViewerVC&dataset_id=home/env/temperature
Same flow as ConsentVC, but with type=ViewerVC. Send the QR/deeplink
to the wallet by scanning the QR code (with an iPhone and a Mac you can also send the deeplink via AirDrop) and store the credential.
The wallet should display a separate card with claims:
dataset_id:home/env/temperatureallowed_actions:["read"]
4. Present the ViewerVC¶
In the PC browser:
http://<HOST_IP>:8080/verifier/request?dataset_id=home/env/temperature&vc_kind=ViewerVC
vc_kind=ViewerVC selects viewer-temperature.json instead of the
ConsentVC-side PD. Send the QR to the wallet, present the credential.
Response the wallet receives (for reference; it is not shown in the PC browser):
{
"status": "allowed",
"dataset_id": "home/env/temperature",
"vc_kind": "ViewerVC",
"viewer_token": "Xa9Hk...",
"viewer_token_jti": "1f2c...",
"expires_in": 60,
"allowed_views": ["event"],
"redirect_uri": "http://<HOST_IP>:8080/viewer?vt=Xa9Hk...&ds=home/env/temperature"
}
5. Read via /platform/data¶
The viewer_token is returned to the wallet as the /verifier/response response, so it is not shown in the PC browser. After the presentation finishes, check the publisher log and copy the value after token= on the viewer_token_issued line.
docker compose -f infra/docker-compose.yml logs publisher 2>&1 | grep viewer_token_issued | tail -n 1
The token's TTL is 60 seconds. Run the next curl within 60 seconds of the log line. If you miss it, present again from §4.
TOKEN='<viewer_token>'
curl -s -H "Authorization: Bearer $TOKEN" \
"http://$HOST_IP:8080/platform/data?dataset_id=home/env/temperature" | python3 -m json.tool
Expected response:
{
"dataset_id": "home/env/temperature",
"count": 1,
"read_count": 1,
"seller_did": null,
"allowed_views": [
"event"
],
"rows": [
{
"dataset_id": "home/env/temperature",
"purpose": "research",
"value": 21.4
}
]
}
rows holds the rows written so far. count is the number of rows, so it changes with how many rows you have written (1 if you wrote once in §2).
read_count shows how many times this token has been used. Within the
60-second TTL the same token can be reused; read_count increments each call.
6. Error cases¶
| Situation | HTTP | detail |
|---|---|---|
| No header | 401 | missing_authorization_header |
| Unknown token | 401 | viewer_token_unknown |
| Expired (60 s elapsed) | 401 | viewer_token_expired |
Query dataset_id mismatch |
403 | viewer_token_dataset_mismatch |
| Tried using a write-side PolicyToken | 401 | viewer_token_unknown (separate token space) |
Verify expiry:
sleep 65
curl -i -H "Authorization: Bearer $TOKEN" \
"http://$HOST_IP:8080/platform/data?dataset_id=home/env/temperature"
# → 401 viewer_token_expired
7. Audit log¶
curl -s "http://$HOST_IP:8080/audit/logs?limit=10" | python3 -m json.tool
The result is a list, newest first. A ViewerVC read is recorded like this (only the first row is shown; the rest is cut as ...):
[
{
"id": ...,
"ts": "...",
"action": "allow",
"subject_did": "did:jwk:...",
"dataset_id": "home/env/temperature",
"purpose": "read",
"reason": "viewer_token_used:1f2c...:1:views=event",
"message_hash": "",
"raw_topic": "platform/data",
"holder_did": "did:jwk:...",
"vc_hash": null,
"presentation_verified": "allow"
},
...
]
reason has the form viewer_token_used:<jti>:<read_count>:views=<allowed_views>. Three reads with the same
token produce three rows with read_count 1, 2, 3.
Symmetry with ConsentVC¶
| Property | ConsentVC (Stage 1) | ViewerVC (Stage 3) |
|---|---|---|
| Purpose | Write authz | Read authz |
| Endpoint | /verifier/request?vc_kind=ConsentVC |
/verifier/request?vc_kind=ViewerVC |
| Token | PolicyToken | ViewerToken |
| TTL | 5 min | 60 s |
| Use | single-use | any number of times within TTL |
| API | POST /platform/ingest |
GET /platform/data |
Audit raw_topic |
platform/ingest |
platform/data |
| VC claim | allowed_purposes |
allowed_actions |
Stop¶
If you go on to the next page, Authenticate machines (Service VC / Stage 4 prep), keep everything running. If you stop here, run the following command.
cd ~/program/Blockchain_IoT_Marketplace
docker compose -f infra/docker-compose.yml --profile ssi-wallet down
Extension ideas¶
- VC expiry: shorten the credential's
expand combine it with revocation (revoke is not implemented yet) - Multi-dataset ViewerVC: extend the schema with
dataset_ids: [...] - Phase 3 integration: have Let an AI plan the steps (LLM Planner) acquire ViewerTokens automatically before each tool call
Troubleshooting¶
- Symptom:
no_presentation_definition_for_dataset - Check:
examples/ssi_wallet/viewer-<dataset>.jsonexists - Check: PD includes
iw3ip_vc_kind: "ViewerVC" - Symptom: wallet shows "no matching credential"
- Check: stored a ViewerVC, not a ConsentVC
- Check: passed
vc_kind=ViewerVCto/verifier/request - Symptom:
/platform/datareturns 401 viewer_token_unknown - Check: not accidentally using a write-side PolicyToken
- Check: the ViewerToken was copied correctly (not cut off)
- Check: the publisher was not recreated after presenting (ViewerTokens and the written data live in the publisher's memory and are lost on recreate; redo the write in §2, then present again in §4)
- Symptom:
/platform/datareturns 401 viewer_token_expired - Action: the TTL (60 s) has expired. Present again from §4
Next steps¶
Next is the other page in 2.3, Authenticate machines (Service VC / Stage 4 prep) (Hands-on).
- Keep the publisher running with the
ssi-walletprofile. Step 1 of the next page starts it with the same command. If you stopped it, step 1 starts it again. - Keep the Quickstart IPFS stopped. IPFS and the publisher both use port 8080.
ViewerVC reads use a directly specified dataset_id. Other forms of authorization are covered on the following pages.
- Authenticate machines (Service VC / Stage 4 prep) — continuous writes from a device (ServiceVC)
- Hand a credential to the buyer's wallet (Bridge / Stage 5) — purchase-bound read (PurchaseViewerVC)
- Read ServiceVC-written data with a PurchaseViewerVC (Stage 6) — capstone of Stage 1–5
- Back the seller's identity (Seller VC / Stage 7) — seller identity
References¶
[1] OpenID Foundation, "OpenID for Verifiable Credential Issuance 1.0," https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html
[2] OpenID Foundation, "OpenID for Verifiable Presentations 1.0," https://openid.net/specs/openid-4-verifiable-presentations-1_0.html