How often can a pre-authorized code be redeemed, and which tx_code errors apply?
Pre-authorized code single use and tx_code error mappingOID4VCI 1.0 §6.1MUSTRoles: authorization_server
Requirement as recorded in the ProtocolSoup registry
A pre-authorized code is accepted at most once under concurrent exchange, a required missing tx_code is invalid_request, an unexpected tx_code is invalid_request, and a wrong required tx_code is invalid_grant.
Read §6.1 in OID4VCI 1.0Self-test verdict
PassCommit 00bac3fEvaluated
This is ProtocolSoup's result against its own implementation at the commit shown. It is not a certification of ProtocolSoup or of any other product.
Captured from production
Captured Commit 00bac3f
Captured from the deployed ProtocolSoup at the commit shown. Every request and response is shown exactly as sent and received.
Passing exchange
Accepted, as requiredConformance client
The conformance client redeems a fresh pre-authorized code at /oid4vci/token with the tx_code the issuer delivered out of band.
Requests from ProtocolSoup’s conformance client, which sends malformed messages on purpose. The hosted wallet never sends these.
1.POST https://protocolsoup.com/oid4vci/token200 OK
TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2
Request
POST /oid4vci/token HTTP/2.0 Content-Length: 141 Content-Type: application/x-www-form-urlencoded Host: protocolsoup.com User-Agent: ProtocolSoup-Conformance-Client/1 grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code&pre-authorized_code=2nOS-FvXS67kNp2N9XCPwTwT7742VbGj&tx_code=750547
Response
HTTP/2.0 200 OK Cache-Control: no-store Cf-Cache-Status: DYNAMIC Cf-Ray: a65b91c79f9e1425-MSP Content-Type: application/json Date: Sun, 06 Dec 2026 13:17:12 GMT Fly-Request-Id: 01M95R0P6X0HJ94HQZ6W9W4SBW-ord Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800} Pragma: no-cache Referrer-Policy: strict-origin-when-cross-origin Report-To: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=zuCMaj6jpynn05vF0RNPEuj670LPAsO4KS5JxXRwMR2O8Ii3ga1GQWZoujRDmaLnj10HdSnmJWcFDBXQ9u0Y1DEl5B%2FY25UDFDAqD7Un23%2BV9B3VjWliMjP94kMIC%2FO%2Ftq0%3D"}]} Server: cloudflare Server-Timing: cfCacheStatus;desc="DYNAMIC" Server-Timing: cfEdge;dur=21,cfOrigin;dur=200 Vary: Origin Vary: accept-encoding Via: 1.1 fly.io, 1.1 fly.io X-Content-Type-Options: nosniff X-Frame-Options: DENY X-Xss-Protection: 1; mode=block {"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6InJzYS05YTJlNThlYzVjNjk3NGJmIiwidHlwIjoiSldUIn0.eyJhdWQiOiJodHRwczovL3Byb3RvY29sc291cC5jb20vb2lkNHZjaSIsImNyZWRlbnRpYWxfY29uZmlndXJhdGlvbl9pZHMiOlsiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWxTREpXVCJdLCJleHAiOjE3OTY1NjMzMzIsImlhdCI6MTc5NjU2MzAzMiwiaXNzIjoiaHR0cHM6Ly9wcm90b2NvbHNvdXAuY29tL29pZDR2Y2kiLCJqdGkiOiJqdGktYmUzNzE1OTM1NTQ3Zjg5YiIsIm5iZiI6MTc5NjU2MzAzMiwib2ZmZXJfaWQiOiJPaWxLTEpXbks4TWZ1Q2w3eXR6ZWRaMTEiLCJzY29wZSI6InZjOmlzc3VlIiwic3ViIjoid2FsbGV0Ok9pbEtMSlduSzhNZnVDbDd5dHplZFoxMSJ9.l0vXuN6R9qNrGCQlRo_VOxEHCStFQ93tsScNUwgofcyiyKC_hw0Kq6Gr5Qaz8-SJ7rTle-G6SRfrCWA8DP77r7bFnm5CWF2EJOgxfXm8Bx4BhoWhspfECKxPCKX4y9P4T0ezQeBs8NQbBHB8NYkteDdqYysf9J5t6NwDPGqDdbYW7QOXFioxrmy3lMUJ02zgkP4-Yz72OIKd-C5Na2bMGfhEboct_Dvds7x4qKBXMEjSCN6_AF9Nop4KyvMTGbD7mpepajnfETh9GRsdjit6NlSc9CfjMYis3rIccL-5T6bnKpGCGRYhFr9dKv9KB90uvFu9llEsvh64YKB_zeHaLA","expires_in":300,"scope":"vc:issue","token_type":"Bearer"}
Failing exchange
Rejected, as requiredConformance client
The conformance client redeems a fresh pre-authorized code with a tx_code that is not the one the issuer delivered.
Requests from ProtocolSoup’s conformance client, which sends malformed messages on purpose. The hosted wallet never sends these.
1.POST https://protocolsoup.com/oid4vci/token400 Bad Request
TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2
Request
POST /oid4vci/token HTTP/2.0 Content-Length: 141 Content-Type: application/x-www-form-urlencoded Host: protocolsoup.com User-Agent: ProtocolSoup-Conformance-Client/1 grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code&pre-authorized_code=RyY8jEIwJhNMlEtDq6NmVpBU_PBTAILI&tx_code=316932
Response
HTTP/2.0 400 Bad Request Cache-Control: no-store Cf-Cache-Status: DYNAMIC Cf-Ray: a65b91d41e041425-MSP Content-Type: application/json Date: Sun, 06 Dec 2026 13:17:14 GMT Fly-Request-Id: 01M95R0R4WTA03ZSZ6WD3FFEZ9-ord Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800} Pragma: no-cache Referrer-Policy: strict-origin-when-cross-origin Report-To: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=xmA%2FR3qFiJgWoftSBHcamqhoaJr8197BqHkp%2BiYPDBDi8%2FTehpn%2BGgNQy6avKJokCUszCta0InDEY49xi1Yr6p4mdUPJgmTHH5I2OpjebkAXOO4vOqD3CbonfMTbGrruMQ0%3D"}]} Server: cloudflare Server-Timing: cfCacheStatus;desc="DYNAMIC" Server-Timing: cfEdge;dur=3,cfOrigin;dur=209 Vary: Origin Vary: accept-encoding Via: 1.1 fly.io, 1.1 fly.io X-Content-Type-Options: nosniff X-Frame-Options: DENY X-Xss-Protection: 1; mode=block {"error":"invalid_grant","error_description":"invalid tx_code"}
Run it live
Looking Glass runs the flow that sends the message this requirement governs, against the same server, and decodes each exchange as it happens.
Open the flow in Looking GlassTests
- TestPreAuthorizedGrantRejectsUnexpectedTxCode
./internal/protocols/oid4vci
Pass - TestPreAuthorizedGrantDistinguishesMissingAndWrongTxCode
./internal/protocols/oid4vci
Pass - TestPreAuthorizedGrantExchangeIsAtomic
./internal/protocols/oid4vci
Pass
Implementation
Explainer
What this requires
The single-use rule comes from Section 4.1.1, where pre-authorized_code is defined: "This code MUST be short lived and single use." Section 6.1 sets the Token Request rule for tx_code: "This value MUST be present if a tx_code object was present in the Credential Offer (including if the object was empty)."
Section 6.3 maps the failures to error codes. invalid_request covers both "The Authorization Server does not expect a Transaction Code in the Pre-Authorized Code Flow but the Client provides a Transaction Code" and the case where one is expected but not provided. invalid_grant covers "The Authorization Server expects a Transaction Code in the Pre-Authorized Code Flow but the Client provides the wrong Transaction Code."
Why it exists
Section 13.6.1 explains the risk: "The Pre-Authorized Code Flow is vulnerable to the replay of the Pre-Authorized Code, because by design, it is not bound to a certain session". A QR code can be photographed over a shoulder or forwarded. Single use limits the code to one redemption, and the Transaction Code binds that redemption to someone who received the code through a second channel.
The two error codes tell the Wallet different things. invalid_request means the request was the wrong shape for this offer. invalid_grant means the code or the Transaction Code was wrong.
What non-compliance looks like
Two Wallets, or one Wallet and an attacker, post the same pre-authorized_code at the same time, and both receive tokens because the check and the update are not atomic. Other failures are an issuer that returns invalid_grant for a missing tx_code, or that silently ignores a tx_code the offer never asked for.
How ProtocolSoup tests it
handlePreAuthorizedTokenGrant in handlers.go returns invalid_grant for an unknown, already exchanged or expired code; offers expire after 15 minutes. A missing required tx_code gets invalid_request ("tx_code is required"), an unexpected one gets invalid_request ("tx_code was not expected"), and a wrong one gets invalid_grant ("invalid tx_code"), all with HTTP 400. The supplied value is compared with subtle.ConstantTimeCompare, so response timing does not reveal how much of the code matched; only its length, which the offer's tx_code object already publishes, can affect the timing. Under the plugin mutex, the handler re-reads the offer, marks it exchanged and deletes the code mapping before minting the token. A concurrent loser gets invalid_grant ("pre-authorized code has already been exchanged").
TestPreAuthorizedGrantRejectsUnexpectedTxCode sends tx_code for an offer without one and asserts 400 invalid_request. TestPreAuthorizedGrantDistinguishesMissingAndWrongTxCode asserts invalid_request for a missing value and invalid_grant for a wrong value on an offer that requires one. TestPreAuthorizedGrantExchangeIsAtomic sends two concurrent Token Requests with the same code and asserts exactly one 200 and one 400. It does not check the loser's error code.