OAuth 2.0
| Type | Authorization framework |
|---|---|
| Standard | RFC 6749 (IETF, October 2012), replacing OAuth 1.0 |
| Security practice | RFC 9700, BCP 240 (January 2025) |
| Extensions | RFC 7636 PKCE; OpenID Connect for sign-in |
| OWASP Top 10 | A07:2025 Authentication Failures |
| Used by | "Sign in with" buttons, apps that connect to GitHub or Google accounts, Supabase Auth social providers |
A printing service wants to print photos that a user keeps on a photo-sharing site. Without a common protocol, the user types the photo site's password into the printing service, which then has the whole account. Cutting off that one service means changing the password, which cuts off every other service that holds it too.1 With OAuth 2.0 the user approves the request at the photo site itself, and the printing service receives an access token: a string tied to a stated set of permissions and a lifetime.1
Roles and tokens
Four parties take part. The resource owner is usually the person who owns the account. The resource server holds the data, such as the photo site's API. The client is the application asking for access, whether it runs on a server, a desktop or a phone. The authorization server signs the owner in, asks for approval and issues tokens.1
An access token carries a scope, the list of things it allows; broad scopes make an Over-privileged access token. A client may also hold a refresh token, which it trades for new access tokens later without the user being present.2 Approvals and tokens left in place after their use ends are Orphaned access tokens and OAuth grants.
The authorization code flow
In the authorization code flow, the client sends the browser to the authorization server with the client's identifier, the scope, a random state value and the address to return to:1
GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.comAfter the user signs in and approves, the server redirects the browser back with a one-time code:
HTTP/1.1 302 Found
Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA&state=xyzThe client's server then sends the code straight to the authorization server's token endpoint and receives the access token in the response. The token never passes through the browser, and the password goes only to the authorization server.1 The code is tied to the client and the redirect address, works once, and should expire within ten minutes.1 Supabase Auth gives its codes five minutes and accepts each one once, through exchangeCodeForSession(code).3
PKCE
A code that leaks can still be redeemed by whoever holds it. On a phone, the return address often uses a custom scheme such as myapp://, and a second app can register the same scheme and receive the code.4 PKCE closes this. Before each request, the client generates a random code_verifier of 43 to 128 characters and sends only its SHA-256 hash, the code_challenge, with code_challenge_method=S256. At the token endpoint it sends the verifier itself; the server hashes it and compares. A thief holding the code lacks the verifier, so the exchange fails.4
PKCE was designed for phone apps, but RFC 9700 applies it to web applications as well. A client that cannot keep a secret must use it; for a server-side client it is recommended. Every authorization server must support it.5
Retired grant types
The 2012 specification also defined the implicit grant, the password grant and client credentials, the last for an application acting for itself.1 The implicit grant returned the access token directly in the redirect address, after the #, without authenticating the client, which left the token readable by anything with access to the browser.1 The password grant had the client collect the user's password. Clients should no longer use the implicit grant, and the password grant must not be used at all.5
OAuth and sign-in
OAuth delegates access and says nothing about who the user is. A client holding an access token cannot tell whether the user is still there, since a refresh token renews access after the user has left.2 The token is addressed to the API, not to the client. A client that treats "this token works on the profile endpoint" as a login can be handed a valid token issued to a different app and log the attacker in as that token's user.2
OpenID Connect, published in 2014, adds the missing layer.2 Next to the access token the client receives an ID token, a signed JWT that names the user, the issuer and the client it was made for. The client must reject an ID token whose aud (audience) field does not contain its own client ID.6 Google's sign-in runs on OpenID Connect.2
Redirect addresses
The authorization server must compare the redirect address with the registered one character for character, with one exception for port numbers on localhost in phone and desktop apps. Neither side may host an Open redirect, a page that forwards the browser to any address in a query parameter, because the code would travel on with it.5 The state value, or PKCE, stops a forged callback in which an attacker's code is pushed into the victim's session, the OAuth form of Cross-site request forgery.5
In Supabase, the allowed addresses are listed under Redirect URLs on the URL Configuration page, and the Site URL on the same page should be changed from http://localhost:3000 to the production address. Wildcards such as ** suit local development and preview builds; Supabase advises an exact path for production.7
Stolen tokens: GitHub, April 2022
On 12 April 2022 GitHub found that someone had used a compromised AWS key to reach npm's production systems. GitHub believed the key came from private npm repositories downloaded with a stolen OAuth token. The tokens belonged to OAuth apps run by Heroku and Travis CI, which GitHub users had connected to their accounts, and were used to download private repositories from dozens of organizations. GitHub listed five affected apps: four Heroku Dashboard apps and Travis CI. GitHub said it did not believe the tokens came from its own systems, since it does not store them in a usable form, and asked both companies to revoke every user token of the affected apps. It suspected the attacker was searching the downloaded code for secrets that would open other systems.8
In SecFlash
SF-EXP-607 on the Exposure page reports a phone app link that another app can claim, through which a sign-in code can reach the wrong app. SF-SEC-742 on the Security page reports code that redirects to an address taken from the request, and SF-SEC-606 reports an open redirect found on the running site.
See also
- Authentication
- JSON Web Token
- Orphaned access tokens and OAuth grants
- Over-privileged access token
- Open redirect
- Session management
- Phishing
- Responding to an administrator account takeover
- Category: Authentication
References
- a b c d e f g h Hardt, D., ed. (October 2012). "The OAuth 2.0 Authorization Framework". RFC 6749. IETF.
- a b c d e Richer, J. "User Authentication with OAuth 2.0". oauth.net.
- back Supabase (12 August 2026). "PKCE flow". Supabase Docs.
- a b Sakimura, N., Bradley, J. and Agarwal, N. (September 2015). "Proof Key for Code Exchange by OAuth Public Clients". RFC 7636. IETF.
- a b c d IETF (January 2025). "Best Current Practice for OAuth 2.0 Security". RFC 9700. IETF.
- back OpenID Foundation. "OpenID Connect Core 1.0 incorporating errata set 2". OpenID Foundation.
- back Supabase (2026). "Redirect URLs". Supabase Docs.
- back GitHub (15 April 2022, updated 22 April 2022). "Security alert: Attack campaign involving stolen OAuth user tokens issued to two third-party integrators". The GitHub Blog.
External links
- RFC 9700: Best Current Practice for OAuth 2.0 Security, IETF
- OAuth 2.0, oauth.net