What is the recommended maximum lifetime of an authorization code?
Authorization code lifetime of at most 10 minutesRFC 6749 §4.1.2RECOMMENDEDRoles: authorization_server
Requirement as recorded in the ProtocolSoup registry
A maximum authorization code lifetime of 10 minutes is RECOMMENDED.
Read §4.1.2 in RFC 6749Self-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 and redeems the authorization code at the token endpoint within seconds of receiving it. 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.GET https://protocolsoup.com/oauth2/authorize?client_id=public-app&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback&response_type=code&scope=profile&state=Pn-FE_uaIPKIoIUH1L_hsQ200 OK
TLS: TLS 1.3 · TLS_AES_128_GCM_SHA256 · h2
Request
GET /oauth2/authorize?client_id=public-app&redirect_uri=https%3A%2F%2Fprotocolsoup.com%2Fcallback&response_type=code&scope=profile&state=Pn-FE_uaIPKIoIUH1L_hsQ 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: a65ba717d9143cdb-MSP Content-Type: text/html Date: Sun, 06 Dec 2026 13:31:45 GMT Fly-Request-Id: 01M95RVAQQ8S45WYBYNR5YET3N-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=%2Fwn65dg4K0pq3oLoD4lGLeRwD6vvfDcraQNNU0QCL%2BVC%2BBX9plBYKRefr4hmUgc3EyCGjiYD1ZZUhwP4%2BgTeBLHdwCAKF%2FzX%2FIyI8MZhm4rQ39vDqCkUZJmhO3QbEXnfWBA%3D"}]} Server: cloudflare Server-Timing: cfCacheStatus;desc="DYNAMIC" Server-Timing: cfEdge;dur=5,cfOrigin;dur=198 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="PexutiTkmdl7f04nTG3p4Q"> <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="9efff2f7fdfbdefbe6fff3eef2fbb0fdf1f3">[email 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="9cfef3fedcf9e4fdf1ecf0f9b2fff3f1">[email 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="6b0a0f0602052b0e130a061b070e45080406">[email 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:'a65ba717d9143cdb',t:'MTc5NjU2MzkwNQ=='};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=a65ba717d9143cdb',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.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: 143 Content-Type: application/x-www-form-urlencoded Host: protocolsoup.com User-Agent: ProtocolSoup-Conformance-Client/1 client_id=public-app&code=HRGrO6ytYbfEbv6o-36VAatPgZbmORLo&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: a65ba72a98b63cdb-MSP Content-Type: application/json Date: Sun, 06 Dec 2026 13:31:48 GMT Fly-Request-Id: 01M95RVDNEXNNCH4J33CBZE7YD-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=omjYwToSFsYKIXpv9O%2BIZiGajpz7gutrmPbCyuKwFjosoPQmQhl5vKXAuZ9yAb6kti%2B65kqQY7ctIaZUPdSQapBxLQcXN6WOcLnwRSxKUntdDHcqtcVtOwB9FfqgMSzQS1M%3D"}]} Server: cloudflare Server-Timing: cfCacheStatus;desc="DYNAMIC" Server-Timing: cfEdge;dur=3,cfOrigin;dur=251 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.eyJhdWQiOiJodHRwczovL3Byb3RvY29sc291cC5jb20vb2F1dGgyL3Jlc291cmNlIiwiYmlydGhkYXRlIjoiMTk5MC0wMy0xMiIsImNsaWVudF9pZCI6InB1YmxpYy1hcHAiLCJleHAiOjE3OTY1Njc1MDgsImZhbWlseV9uYW1lIjoiSm9obnNvbiIsImdlbmRlciI6ImZlbWFsZSIsImdpdmVuX25hbWUiOiJBbGljZSIsImlhdCI6MTc5NjU2MzkwOCwiaXNzIjoiaHR0cHM6Ly9wcm90b2NvbHNvdXAuY29tL29hdXRoMiIsImp0aSI6Imp0aS1hZWNmYzAyOGIyZGI2NWQ2IiwibG9jYWxlIjoiZW4tQVUiLCJtaWRkbGVfbmFtZSI6Ik1hcmllIiwibmFtZSI6IkFsaWNlIEpvaG5zb24iLCJuYmYiOjE3OTY1NjM5MDgsIm5pY2tuYW1lIjoiQWxpIiwicGljdHVyZSI6Imh0dHBzOi8vd3d3LnByb3RvY29sc291cC5jb20vdS9hbGljZS9hdmF0YXIucG5nIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWxpY2UiLCJwcm9maWxlIjoiaHR0cHM6Ly93d3cucHJvdG9jb2xzb3VwLmNvbS91L2FsaWNlIiwic2NvcGUiOiJwcm9maWxlIiwic3ViIjoiYWxpY2UiLCJ1cGRhdGVkX2F0IjoxNzk2NTYyNjkzLCJ3ZWJzaXRlIjoiaHR0cHM6Ly9hbGljZS5leGFtcGxlLmNvbSIsInpvbmVpbmZvIjoiQXVzdHJhbGlhL1N5ZG5leSJ9.CpNiOdtygIghzCgv-01Uo1LXCZOVa29vmEYan5roGDNmS_1UNq-X-B8uYyMAhqTfL5hbVrbWhn6o-E9U2GtrFR47RYopD4oih7UW6jIjJA7FP27378LkNqXE7LjdaDAHDUZXTwl0NGykgIHYNUDVgD4-WTeNPBpQkYjZgEWPle1QtyRh-FtINzBsun9WDqt3jRIygQKZiBhSs4JRxEVTUhFF4AWxZKU5satA5l9UeuMLWg45k5dRICczXJNnIOf2sabXNTsckF2ak290sSxI3ki3UWlJlJslKph2-c3E-sjh79CcL-FM_qNltl6xiAzazzduNHu3VABOZ21wCkTnkg","token_type":"Bearer","expires_in":3600,"refresh_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6InJzYS05YTJlNThlYzVjNjk3NGJmIiwidHlwIjoiSldUIn0.eyJjbGllbnRfaWQiOiJwdWJsaWMtYXBwIiwiZXhwIjoxNzk3MTY4NzA4LCJpYXQiOjE3OTY1NjM5MDgsImlzcyI6Imh0dHBzOi8vcHJvdG9jb2xzb3VwLmNvbSIsImp0aSI6InJlZnJlc2gtYmZiNDZhNTgwM2RjZTNlNSIsInNjb3BlIjoicHJvZmlsZSIsInN1YiI6ImFsaWNlIiwidHlwZSI6InJlZnJlc2gifQ.Wviy58unRvYDz2_dxys7GqGgSLSxV3Co5bDcLUdXkC02qKMmqwj8H-FiolIvTdlOuakcD7POQonLLoYEegqEd_nAJVcizfLWEGBvZeuo586YrhMfYMlrpSbYKv19evHYcziIAU035R_snNMR4L2waEj6vFBmnTL8FpTCe0PeW79JEoy_3Hoz5Gyx7i_qCjI6n8mkOOAcW2EW5BS7xHdO0G5W1enVQ7MMWL1TC7UXjB8DqDkLaJtGJeA5jKz5qlYBdjU6pl9PWfdLCIk75SDjzgmSKqg0cIAPVLvTY3iJRfk5kbYhIk22mZE9bwuLGasqlMIMx2Vtj21pnuLK1qnqmg","scope":"profile"}
Failing exchange
Rejected, as requiredConformance client
The conformance client obtains an authorization code as public-app, waits 65 seconds, and then sends the token request for it. This authorization server's codes expire 60 seconds after they are issued.
Requests from ProtocolSoup’s conformance client, which sends malformed messages on purpose. The hosted wallet never sends these.
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: 143 Content-Type: application/x-www-form-urlencoded Host: protocolsoup.com User-Agent: ProtocolSoup-Conformance-Client/1 client_id=public-app&code=wVg3e2rHnpHgRDyBhs2p6SnqUgcHADo8&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: a65ba8db58be3cdb-MSP Content-Type: application/json Date: Sun, 06 Dec 2026 13:32:57 GMT Fly-Request-Id: 01M95RXH98ZFWV2W1NPEGGB9JS-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=Lt%2FQrleO3b6y4DcVs%2BFdlC4WmAOhaqa3VlxKe8DVKl5VoVI11qpHmfhFGK88I2a%2B%2B75h%2BfmYVmqjXiFOVKjG8AL4ZiUctTB9qwjcoSv7%2B01KMnjor0CZHSnS3jLKm3M%2FFQs%3D"}]} Server: cloudflare Server-Timing: cfCacheStatus;desc="DYNAMIC" Server-Timing: cfEdge;dur=8,cfOrigin;dur=198 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":"authorization code expired","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 GlassTests
- TestExpiredAuthorizationCodeIsRefused
./internal/protocols/oauth2
Pass - TestAuthorizationCodeLifetimeIsAtMostSixtySeconds
./internal/mockidp
Pass
Implementation
Explainer
What this requires
The recommended maximum lifetime of an authorization code is ten minutes. That is the upper bound RFC 6749 gives for how long a code stays redeemable, and it turns the "shortly" of the preceding sentence into a number. It is a RECOMMENDED ceiling and not a target: a server may choose any shorter lifetime, and most have reason to.
The right value depends on what happens between the authorization response and the token request. For a web or native client that step is automatic and takes well under a second on a healthy network. Ten minutes allows for a slow device and a retry. Nothing in an ordinary flow needs more.
Why it exists
"Shortly" alone would be read differently by every implementer. A number gives clients something to design against and gives reviewers something to check. The ceiling is generous because the RFC was written for a wide range of clients, and because single use, required alongside it, limits the damage a longer-lived code can do.
Later security profiles shortened it. A minute is common where the client is known to exchange the code immediately.
What non-compliance looks like
A code lifetime measured in hours, usually inherited from a session or cache default. Since this is a recommendation, a longer lifetime is a deviation to justify and document, and the justification is hard to find: the legitimate client never needs it.
The opposite error is a lifetime so short that clock differences between the nodes of a clustered authorization server cause valid codes to be refused.
How ProtocolSoup tests it
This server's codes live 60 seconds, a tenth of the recommended maximum. The value is a single constant in the Mock IdP, and all three authorization servers in the sandbox issue codes through it.
TestAuthorizationCodeLifetimeIsAtMostSixtySeconds creates a code and asserts its expiry falls within a second or two of that constant from now, and that the constant itself is no more than 60 seconds. TestExpiredAuthorizationCodeIsRefused checks the bound from the outside: a code issued through /oauth2/authorize has a remaining lifetime of at most ten minutes, and a code past its expiry is refused at /oauth2/token with invalid_grant.
The captured passing exchange is code-redeemed-at-once. The failing one, code-redeemed-after-65-seconds, waits past the 60 seconds and records 400 invalid_grant with authorization code expired.