What error does the token endpoint return when the code_verifier does not match?

invalid_grant when the code_verifier does not matchRFC 7636 §4.6MUSTRoles: authorization_server

Requirement as recorded in the ProtocolSoup registry

If the values are not equal, an error response indicating "invalid_grant" as described in Section 5.2 of [RFC6749] MUST be returned.

Read §4.6 in RFC 7636

Self-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 sends public-app's authorization request with the code_challenge of RFC 7636 Appendix B and code_challenge_method=S256, and redeems the code with the Appendix B code_verifier. The values are equal and tokens are issued. The sign-in between the two requests is not recorded.

Requests from ProtocolSoup’s conformance client, which sends malformed messages on purpose. The hosted wallet never sends these.

  1. 1.GET https://protocolsoup.com/oauth2/authorize?client_id=public-app&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback&response_type=code&scope=profile&state=yX3A5ZnXmBOZexMNdxfCeg200 OK

    TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2

    Request

    GET /oauth2/authorize?client_id=public-app&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback&response_type=code&scope=profile&state=yX3A5ZnXmBOZexMNdxfCeg HTTP/2.0
    Accept: text/html
    Host: protocolsoup.com
    User-Agent: ProtocolSoup-Conformance-Client/1
    
    

    Response

    HTTP/2.0 200 OK
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: a65bb0cf5a473cdb-MSP
    Content-Type: text/html
    Date: Sun, 06 Dec 2026 13:38:23 GMT
    Fly-Request-Id: 01M95S7FD4TA8GA3EV5H8QDGJQ-ord
    Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
    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=HkG8dG1fJqJpUhyUKbsKENZFGKrgtA99KNVJFfcUFfoU45liiq56D7wz20Paf1ROVKwQaED8ebRvMpk%2FyDeDtAVyvEicE%2FNwQgzG15ub6bmSfwu9zSmfmTcmoODG0XTtx5w%3D"}]}
    Server: cloudflare
    Server-Timing: cfCacheStatus;desc="DYNAMIC"
    Server-Timing: cfEdge;dur=3,cfOrigin;dur=196
    Speculation-Rules: "/cdn-cgi/speculation"
    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
    
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <title>Login - Protocol Showcase</title>
        <style>
    
            * { box-sizing: border-box; margin: 0; padding: 0; }
            body {
                font-family: 'Segoe UI', system-ui, sans-serif;
                background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
                min-height: 100vh;
                display: flex;
                align-items: center;
                justify-content: center;
                color: #e4e4e7;
                padding: 16px;
            }
            .container {
                background: rgba(255, 255, 255, 0.05);
                backdrop-filter: blur(10px);
                border: 1px solid rgba(255, 255, 255, 0.1);
                border-radius: 16px;
                padding: 28px;
                width: 100%;
                max-width: 420px;
                box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
            }
            @media (min-width: 480px) {
                body { padding: 0; }
                .container { padding: 40px; }
            }
            .logo {
                text-align: center;
                margin-bottom: 30px;
            }
            .logo h1 {
                font-size: 24px;
                font-weight: 600;
                color: #fff;
            }
            .logo p {
                color: #a1a1aa;
                font-size: 14px;
                margin-top: 8px;
            }
            .client-info {
                background: rgba(99, 102, 241, 0.1);
                border: 1px solid rgba(99, 102, 241, 0.2);
                border-radius: 8px;
                padding: 16px;
                margin-bottom: 24px;
                text-align: center;
            }
            .client-info span {
                color: #a5b4fc;
                font-size: 14px;
            }
            .client-info strong {
                color: #fff;
            }
            .form-group {
                margin-bottom: 20px;
            }
            label {
                display: block;
                font-size: 14px;
                font-weight: 500;
                margin-bottom: 8px;
                color: #d4d4d8;
            }
            input[type="email"], input[type="password"], input[type="text"] {
                width: 100%;
                padding: 12px 16px;
                border: 1px solid rgba(255, 255, 255, 0.1);
                border-radius: 8px;
                background: rgba(0, 0, 0, 0.2);
                color: #fff;
                font-size: 16px;
                transition: all 0.2s;
            }
            input:focus {
                outline: none;
                border-color: #6366f1;
                box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
            }
            button {
                width: 100%;
                padding: 14px;
                background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
                border: none;
                border-radius: 8px;
                color: #fff;
                font-size: 16px;
                font-weight: 600;
                cursor: pointer;
                transition: transform 0.2s, box-shadow 0.2s;
            }
            button:hover {
                transform: translateY(-2px);
                box-shadow: 0 10px 20px -10px rgba(99, 102, 241, 0.5);
            }
            .error {
                background: rgba(239, 68, 68, 0.1);
                border: 1px solid rgba(239, 68, 68, 0.2);
                color: #fca5a5;
                padding: 12px;
                border-radius: 8px;
                margin-bottom: 20px;
                font-size: 14px;
            }
            .demo-users {
                margin-top: 24px;
                padding-top: 24px;
                border-top: 1px solid rgba(255, 255, 255, 0.1);
            }
            .demo-users h3 {
                font-size: 14px;
                color: #a1a1aa;
                margin-bottom: 12px;
            }
            .demo-user {
                background: rgba(0, 0, 0, 0.2);
                border: 1px solid rgba(255, 255, 255, 0.05);
                border-radius: 8px;
                padding: 12px;
                margin-bottom: 8px;
                cursor: pointer;
                transition: all 0.2s;
            }
            .demo-user:hover {
                background: rgba(99, 102, 241, 0.1);
                border-color: rgba(99, 102, 241, 0.2);
            }
            .demo-user .name {
                font-weight: 500;
                color: #fff;
            }
            .demo-user .email {
                font-size: 12px;
                color: #71717a;
            }
            .scopes {
                margin-top: 16px;
                font-size: 12px;
                color: #71717a;
            }
            .scopes span {
                display: inline-block;
                background: rgba(99, 102, 241, 0.1);
                padding: 4px 8px;
                border-radius: 4px;
                margin: 2px;
            }
    
        </style>
    </head>
    <body>
        <div class="container">
            <div class="logo">
                <h1>Protocol Showcase</h1>
                <p>OAuth 2.0 Authorization</p>
            </div>
            
            <div class="client-info">
                <span>Signing in to <strong>Public Application (SPA)</strong></span>
            </div>
    
            <!-- ERROR -->
    
            <form method="POST" action="/oauth2/authorize">
                <input type="hidden" name="login_request_id" value="Z7dj22jQUP_VEZTw0_y85A">
                
                <div class="form-group">
                    <label for="email">Email</label>
                    <input type="email" id="email" name="email" placeholder="[email protected]" required>
                </div>
                
                <div class="form-group">
                    <label for="password">Password</label>
                    <input type="password" id="password" name="password" placeholder="password" required>
                </div>
                
                <button type="submit">Sign In</button>
            </form>
    
            <div class="demo-users"><h3>Demo Users (click to autofill)</h3><div class="demo-user" data-email="[email protected]" data-password="4bbw3nqtTsR9az7s2albdeeu" onclick="fillCredentials(this.dataset.email || '', this.dataset.password || '')"><div class="name">Alice (Standard User)</div><div class="email"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01606d686264416479606c716d642f626e6c">[email&#160;protected]</a></div></div><div class="demo-user" data-email="[email protected]" data-password="6PdvnYFdfrvoyxTXbzmHF9c1" onclick="fillCredentials(this.dataset.email || '', this.dataset.password || '')"><div class="name">Bob (Standard User)</div><div class="email"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b6bbb694b1acb5b9a4b8b1fab7bbb9">[email&#160;protected]</a></div></div><div class="demo-user" data-email="[email protected]" data-password="ETi7vCbBBwojO-wKkmBZp81Q" onclick="fillCredentials(this.dataset.email || '', this.dataset.password || '')"><div class="name">Admin (Elevated Permissions)</div><div class="email"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a0b0e0703042a0f120b071a060f44090507">[email&#160;protected]</a></div></div></div>
    
            <div class="scopes">
                Requested scopes: <span>profile</span>
            </div>
        </div>
    
        <script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script><script>
            function fillCredentials(email, password) {
                document.getElementById('email').value = email;
                document.getElementById('password').value = password;
            }
        </script>
    <script>(function(){function c(){var b=a.contentDocument||(a.contentWindow&&a.contentWindow.document);if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'a65bb0cf5a473cdb',t:'MTc5NjU2NDMwMw=='};var l=window.parent.location,o;try{o=new URL(l.origin).origin}catch(e){try{o=new URL(new URL(l.href).origin).origin}catch(e){o=''}}var u='/cdn-cgi/challenge-platform/scripts/jsd/main.js?ray=a65bb0cf5a473cdb',a=document.createElement('script');a.src=o?new URL(u,o).href:u;document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script><script type="module" src="https://static.cloudflareinsights.com/beacon.min.js/vce701823e78c4301a35b7e07294d87301792088814092" integrity="sha512-UKNk8GbxkABxKcXYuLkO16EleLGUkcvJWtpSNmExE0Too3ZaFAxTscNWEc1OdAv5/BikHawapSCaiD2XCmp+Bw==" data-cf-beacon='{"version":"2024.11.0","token":"4e68ea7d404d48c4b57e5a383f411883","spa":2}' crossorigin="anonymous"></script>
    </body>
    </html>
  2. 2.POST https://protocolsoup.com/oauth2/token200 OK

    TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2

    Request

    POST /oauth2/token HTTP/2.0
    Content-Length: 201
    Content-Type: application/x-www-form-urlencoded
    Host: protocolsoup.com
    User-Agent: ProtocolSoup-Conformance-Client/1
    
    client_id=public-app&code=pSY9C4NodxTFtG0_-89dRs5ZDluJxvek&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback

    Response

    HTTP/2.0 200 OK
    Cache-Control: no-store
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: a65bb0e2183f3cdb-MSP
    Content-Type: application/json
    Date: Sun, 06 Dec 2026 13:38:26 GMT
    Fly-Request-Id: 01M95S7JAYP7CN7NK97Z6CBJS1-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=QKjmfOm78yjd1p4I8DEojflvNfvnuytpY%2Bwz5bKZQylIMON7VT%2FTJBf%2F5gVgKBGBUeHlR2iE5QDxs6zl0d2KK2dL%2B6sNkLbW8H34ce%2BGglWLmJO0EUzM3vHoYegxscSlkP4%3D"}]}
    Server: cloudflare
    Server-Timing: cfCacheStatus;desc="DYNAMIC"
    Server-Timing: cfEdge;dur=3,cfOrigin;dur=207
    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":"eyJhbGciOiJSUzI1NiIsImtpZCI6InJzYS05YTJlNThlYzVjNjk3NGJmIiwidHlwIjoiYXQrand0In0.eyJhdWQiOiJodHRwczovL3Byb3RvY29sc291cC5jb20vb2F1dGgyL3Jlc291cmNlIiwiYmlydGhkYXRlIjoiMTk5MC0wMy0xMiIsImNsaWVudF9pZCI6InB1YmxpYy1hcHAiLCJleHAiOjE3OTY1Njc5MDYsImZhbWlseV9uYW1lIjoiSm9obnNvbiIsImdlbmRlciI6ImZlbWFsZSIsImdpdmVuX25hbWUiOiJBbGljZSIsImlhdCI6MTc5NjU2NDMwNiwiaXNzIjoiaHR0cHM6Ly9wcm90b2NvbHNvdXAuY29tL29hdXRoMiIsImp0aSI6Imp0aS03Yzc1MDYwMGNjOTViMjliIiwibG9jYWxlIjoiZW4tQVUiLCJtaWRkbGVfbmFtZSI6Ik1hcmllIiwibmFtZSI6IkFsaWNlIEpvaG5zb24iLCJuYmYiOjE3OTY1NjQzMDYsIm5pY2tuYW1lIjoiQWxpIiwicGljdHVyZSI6Imh0dHBzOi8vd3d3LnByb3RvY29sc291cC5jb20vdS9hbGljZS9hdmF0YXIucG5nIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWxpY2UiLCJwcm9maWxlIjoiaHR0cHM6Ly93d3cucHJvdG9jb2xzb3VwLmNvbS91L2FsaWNlIiwic2NvcGUiOiJwcm9maWxlIiwic3ViIjoiYWxpY2UiLCJ1cGRhdGVkX2F0IjoxNzk2NTYyNjkzLCJ3ZWJzaXRlIjoiaHR0cHM6Ly9hbGljZS5leGFtcGxlLmNvbSIsInpvbmVpbmZvIjoiQXVzdHJhbGlhL1N5ZG5leSJ9.DDOkmsbA1tstV1oIteR1DkrwjWMn4tEoXo59q5_n2fu5G7wPqQf6ecWPENqKNvSWB5JXl1qWjcgSaqosQeRVlRmeC-mVV1SR95c0ahhyw8GWqkwd4tvvG3tPeujpH9rKg-jnR8erv7HrlV9R_w8G5e0wQt3HxMAXldur7ZEg36bZl9BuUrbTP_p0KnLL2YmHAxAfI01J_M9eworUm5TAsQf1-nj_kCRV2V0nk3f0SBmhZroISxIFmMmAZPsi_t9rxEVPBXdWxV_HTYCM-Wb33_5MNX4SL95UA93q8zcEalv2TZ7FBwuBJokOBtmu_BEj3Q3L9FjoMwbLevNlV_wVog","token_type":"Bearer","expires_in":3600,"refresh_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6InJzYS05YTJlNThlYzVjNjk3NGJmIiwidHlwIjoiSldUIn0.eyJjbGllbnRfaWQiOiJwdWJsaWMtYXBwIiwiZXhwIjoxNzk3MTY5MTA2LCJpYXQiOjE3OTY1NjQzMDYsImlzcyI6Imh0dHBzOi8vcHJvdG9jb2xzb3VwLmNvbSIsImp0aSI6InJlZnJlc2gtMDllZDkwYTBlZTEzYWExMCIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6ImFsaWNlIiwidHlwZSI6InJlZnJlc2gifQ.QF6MwLX72vu4OEQ7qPaZzsxV8t5mD3TidZgSapl0UHcu85f7VxNtzl9AnPkobk_lZkOyb4nBl2q--Kk3potpsc9LoxHjoezq_RDUJj3c_OzYMI0K3Pe2-zZ8FJ915FE7aaXLGc259L5Zvllee4BtuSKrVuGCe380uY0BOY8FfeGCFMxMkzqplmIPmrtpIWjWvhF0x-KJ0ScM55TK0zTKWcDeIirZa2sqOmfKKyOHhMrwS0XGRAHOFp9qPRDnRhCO71I36tGUNUO1p5oU9CMgDS1wQqYH1-yD2KQm7Evkiie_soDtdT6-DMUjvVKydBK_RbisxOzMpjhbH8IEx57nvQ","scope":"profile"}
    

Failing exchange

Rejected, as requiredConformance client

The conformance client obtains an authorization code as public-app with the Appendix B code_challenge, then sends the token request twice with a code_verifier that does not hash to it: another 43-character value, and the Appendix B code_verifier with its last character changed.

Requests from ProtocolSoup’s conformance client, which sends malformed messages on purpose. The hosted wallet never sends these.

  1. 1.POST https://protocolsoup.com/oauth2/token400 Bad Request

    TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2

    Request

    POST /oauth2/token HTTP/2.0
    Content-Length: 201
    Content-Type: application/x-www-form-urlencoded
    Host: protocolsoup.com
    User-Agent: ProtocolSoup-Conformance-Client/1
    
    client_id=public-app&code=2zUiLWhVNJBMlxY9I1UGJ5zmRohl1KDd&code_verifier=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback

    Response

    HTTP/2.0 400 Bad Request
    Cache-Control: no-store
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: a65bb1015cc03cdb-MSP
    Content-Type: application/json
    Date: Sun, 06 Dec 2026 13:38:31 GMT
    Fly-Request-Id: 01M95S7Q76QVM1XKWMPRFS5EJC-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=OEBTRtiTgI8eGBFzvBlwvtwSV1%2FPWjZz2TOQkZHt3FNFmXVtNaGRYattWA3Vx3vCJ5pupyspeDX8YykZ%2FHvIux2UwWYFZVqMtohqq4wHI55ATitphfx9C4t7i1ASYoJ6hYM%3D"}]}
    Server: cloudflare
    Server-Timing: cfCacheStatus;desc="DYNAMIC"
    Server-Timing: cfEdge;dur=4,cfOrigin;dur=210
    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":"code_verifier does not match code_challenge (RFC 7636 Section 4.6)","error_uri":"https://datatracker.ietf.org/doc/html/rfc6749#section-5.2"}
    
  2. 2.POST https://protocolsoup.com/oauth2/token400 Bad Request

    TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2

    Request

    POST /oauth2/token HTTP/2.0
    Content-Length: 201
    Content-Type: application/x-www-form-urlencoded
    Host: protocolsoup.com
    User-Agent: ProtocolSoup-Conformance-Client/1
    
    client_id=public-app&code=2zUiLWhVNJBMlxY9I1UGJ5zmRohl1KDd&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXx&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback

    Response

    HTTP/2.0 400 Bad Request
    Cache-Control: no-store
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: a65bb1079b693cdb-MSP
    Content-Type: application/json
    Date: Sun, 06 Dec 2026 13:38:32 GMT
    Fly-Request-Id: 01M95S7R6DG4WC1ANW19S47M3J-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=gse2FbgJ3or8zahBjxxMQD4ZD5GFRbJu4DGRKb44XXUHwyfRL4qh8XW2La9Do7wfSv61NkuPKOCiy33cS%2F6u3PiMNFRs%2Fq5WYOZWd5Q6rkUalHDeVHlSo1cou63vhXqpVTk%3D"}]}
    Server: cloudflare
    Server-Timing: cfCacheStatus;desc="DYNAMIC"
    Server-Timing: cfEdge;dur=3,cfOrigin;dur=201
    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":"code_verifier does not match code_challenge (RFC 7636 Section 4.6)","error_uri":"https://datatracker.ietf.org/doc/html/rfc6749#section-5.2"}
    

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 Glass

Tests

Implementation

Explainer

What this requires

The token endpoint returns invalid_grant, in the error response RFC 6749 Section 5.2 defines: HTTP 400, a JSON body with an error member, and no tokens. The comparison is the one in RFC 7636 Section 4.6. For S256 the server computes "BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))" and compares the result with the challenge stored for the code.

The error code is fixed by the RFC, and it fits. RFC 6749 defines invalid_grant for a grant that "is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client." A code presented without proof of the verifier is a grant the presenter cannot show is theirs.

Why it exists

This refusal is the whole of PKCE's protection. Section 1 describes the attack: "the attacker intercepts the authorization code returned from the authorization endpoint", and "Once the attacker has gained access to the authorization code, it can use it to obtain the access token." The attacker has the code but not the verifier, which never left the legitimate client. If a wrong or missing verifier is not refused, the interception succeeds.

What non-compliance looks like

A server that logs the mismatch and issues tokens anyway, or that only checks the verifier when one is sent, protects nobody. Returning invalid_request or invalid_client instead is a smaller fault that still breaks clients, which treat those codes as a bug in their own request and not as a rejected grant.

At /oauth2/token a verifier that does not match is answered 400 with error invalid_grant and the error_description code_verifier does not match code_challenge (RFC 7636 Section 4.6). A verifier shorter than 43 characters or with a character outside the unreserved set is refused with the same code. The refusal does not use the code up, so the legitimate client can still redeem it.

How ProtocolSoup tests it

TestCodeVerifierMismatchIsInvalidGrant obtains a code bound to the Appendix B challenge and presents four wrong verifiers: an unrelated 43-character value, the right one with its last character changed, the right one with a character added, and the right one in upper case. Each must be 400 invalid_grant with a JSON body, Cache-Control: no-store and no access_token. The real verifier then succeeds.

The captured passing exchange is matching-code-verifier. The failing one, code-verifier-that-does-not-match, sends two wrong verifiers for a live code.

Related requirements

All RFC 7636 requirements · OAuth 2.0 protocol page