OAuth security best practices
The attacks in this group each have a defense, and the OAuth 2.0A framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. Security Best Current Practice collects them. Read by role, they become a short list for the printer, the photo service and the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests., and most of them became requirements in OAuth 2.1.
Practices for clients
The attacks in this series were not discovered all at once. They were found over the years after OAuth 2.0 was published, in research and in real incidents, and the defenses were written down as they were understood. The OAuth 2.0 Security Best Current Practice, published as RFC 9700 in January 2025, collects them. It updates the original specification, the bearer tokenA token that works for whoever presents it: the API checks that the token is genuine and current, not who is holding it. That is why bearer tokens must be kept from being copied. specification, and the original threat model, and it turns several defenses that were once optional into requirements.
Most of its advice has appeared in the lessons before this one, from Redirect URI validation onward, one attack at a time. Read by role, it becomes a short list for each party. The document separates what a party must do from what it should or may do, and the tables below keep those words. Two rows, on authorization codes and on storing refresh tokens, keep the words of the original specification, which the guidance builds on. Advice phrased without them comes from those lessons.
| Practice | Explained in |
|---|---|
Public clients must use PKCE, and it is recommended for confidential clients. Clients should use the S256 method. | PKCE; Code interception and injection |
| The password grant must not be used, and the implicit grant should not be. | Choosing a flow |
| Clients must prevent forged callbacks, with one-time state bound to the browser session, or with PKCE once they have confirmed that the server enforces it. | Correlating requests and responses; Request correlation and CSRF |
A client working with more than one authorization server must defend against mix-up, and should do so by checking iss. | Authorization server mix-up |
| Clients must not run open redirects. The callback page should not include third-party resources or links to other sites. | Redirects and authorization codes; Redirect URI validation |
| Clients must not send access tokens in a URL query parameter. Send each token only to the API it was issued for. | Using access tokens; Token theft and replay |
| Request only the access the task needs. | Grants, scopes, and consent; Scopes and audiences |
| Refresh tokens must be kept confidential in storage. Under rotation, run one refresh at a time. | Server-rendered web applications; The refresh token grant; Refresh token theft |
The guidance also recommends that authorization servers publish metadata and that clients configure themselves from it where it exists, which reduces the chance of a mistyped or attacker-supplied endpoint.
Practices for resource servers
| Practice | Explained in |
|---|---|
| Validate every token completely. The API must refuse any token not issued for it. | Token formats and validation; Scopes and audiences |
| Check scope and access to the specific object on every request, and never treat a token issued to a client acting for itself as a person's token. | Enforcing access at an API |
| The API must treat received tokens like other sensitive secrets, never storing or passing them on in plain form, which also keeps them out of logs. | Token theft and replay |
| APIs should use sender-constrained tokens. When a token is bound, verify the proof of possession on each request. | Token theft and replay |
Underneath all three roles sits transport security. Authorization responses must never travel over unencrypted connections, which is why the loopback exception is the only place http appears. Between client and API, the guidance recommends TLSTransport Layer Security, the protection behind HTTPS. It encrypts traffic between two connected systems, detects changes on the way, and uses certificates so the client can confirm which server it reached. from end to end. When a proxy ends the TLS connection in front of an API, it must sanitize every incoming header the API relies on for security, such as a forwarded client certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. or address, so an outside caller cannot supply a forged one, and the connection from the proxy to the API must be protected too.
From best practice to OAuth 2.1
Many of these rules change defaults rather than add features, so the OAuth working group has been folding them into the framework itself. OAuth 2.1, still an IETF draft rather than an RFC, consolidates OAuth 2.0 with PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else., the guidance for native and browser applications, bearer tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. usage, and this best current practice. How the specifications evolve sets out what it changes from the original specification.
Because OAuth 2.1 gathers existing guidance rather than inventing new mechanisms, a deployment that follows the original specification together with RFC 9700, as the tables above do, already behaves as OAuth 2.1 describes in most respects.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Audit your lab tenant and its clients against RFC 9700, row by rowFill in the lesson's client, authorization server and resource server tables for your lab tenant, with a real request, an Audit entry or the lab that demonstrates it as evidence for every row.