What RFC 6749 is
Published in 2012, RFC 6749 is the document that defines OAuth 2.0: a delegation framework that lets an application obtain limited access to a user's resources on another service, without ever seeing the user's password. It specifies four ways to get an access token (grant types), of which the authorization code grant is the one used by virtually everything you log into: web apps, SPAs via PKCE, and native apps via RFC 8252.
The core idea: instead of handing your credentials to the application, you authenticate directly with the service that holds the data. That service then issues the application a short-lived access token scoped to exactly what you approved.
The four roles
| Role | Who it is | Example |
|---|---|---|
| Resource owner | The user who owns the data and can grant access. | You, approving a login screen |
| Client | The application asking for access on the user's behalf. | A newsletter dashboard |
| Authorization server | Authenticates the user and issues tokens. | accounts.google.com |
| Resource server | Hosts the protected data and validates access tokens. | gmail API endpoints |
The flow, step by step
- The client sends the browser to the authorization server's
authorizeendpoint withresponse_type=code, itsclient_id, aredirect_uri, the requestedscope, and a randomstatevalue. - The authorization server shows a login and consent screen.
- The user authenticates and approves (or denies) the scopes.
- The authorization server redirects back to the client's
redirect_uriwith a one-timecodeand echoesstateso the client can detect forged callbacks. - The browser follows the redirect; the code lands on the client's callback.
- The client's backend exchanges the code at the
tokenendpoint, authenticating itself with itsclient_secret(or PKCE when it has no secret). - The authorization server validates everything and returns an
access_token(usually with arefresh_token). - The client calls the resource server with
Authorization: Bearerthe access token. - The resource server validates the token and returns the protected data.
- The client renders the page. The token never touched the browser.
Why a code at all?
The obvious question: why not just return the access token in the redirect (the old implicit flow did exactly that)? Because the code is the only piece that passes through the browser, and it is deliberately useless on its own. Step 6 requires client authentication over a back channel, so a code leaked via referrer headers, browser history, or logs cannot be redeemed by an attacker.
SPAs and native apps cannot keep a client_secret, so step 6 authenticates the client differently: with PKCE (RFC 7636), a proof-key handshake you can try right now in thePKCE playground.
Primary sources
- RFC 6749: The OAuth 2.0 Authorization Frameworkrfc-editor.org - the normative text; section 4.1 covers this grant
- oauth.net: Authorization Code Grantoauth.net - the official site's annotated walkthrough