We were doing a security review of an old service on the platform; when we got to the redirect URI field in the OAuth client registration, a teammate said, "wait a minute." The field read: https://*.alan-adimiz.com/*. A wildcard redirect URI — meaning the authorization server was willing to send the token to any subdomain of that domain. Combined with a subdomain takeover, that's a door that serves up user tokens on a silver platter. The application had been in production for three years, and its "Sign in with Google" button was being clicked thousands of times a day.
The "Sign in with Google" button looks innocent; the protocol family behind it, when set up wrong, can turn the slickest application into a security wreck. The good news: with OAuth 2.1, the rules are clearer than ever. In this post I'll cover both what 2.1 changes and which flow is right for which scenario, with examples from the field.
OAuth 2.1: not innovation, but pruning
Don't think of OAuth 2.1 as a feature release; it didn't bring any new capabilities. What it does is gardening — it officially cut away a decade of bad practices. The implicit flow is dead: that old flow, where the access token was carried in the URL fragment, is now outside the specification; tokens don't travel in URLs, period. The password grant is dead: having users type their password into a third-party application (remember when some apps would say "enter your Gmail password"?) is officially history. And PKCE has become mandatory for everyone — the mechanism once described as "recommended for mobile apps" is now standard for all clients, including server-side web applications.

Let me explain in two sentences what PKCE is for, because just saying "it's mandatory now" and moving on wouldn't do it justice. The authorization code returned by the authorization server travels somewhere (on a mobile device, in a browser) before it's exchanged for a token, and it can be stolen along the way. PKCE binds that code to the client with a one-time secret generated at the start of the flow: whoever steals the code can't get a token because they don't have the secret. The cost is a few lines of code; the hole it closes is a class of attack that has been exploited many times in the real world. That's why making it mandatory was the right call.
If you still have a system running on the implicit flow or the password grant, take it off the "we'll look at it someday" list and put it on this quarter's plan. Identity providers are shutting these flows down one by one; you'll want to migrate during a calm period, not in the middle of a crisis.
Which flow for which scenario
The mapping we've used on projects for years actually fits in four lines:
- Server-side web application: Authorization Code + PKCE. Tokens stay on the server; the browser only receives a session cookie with the HttpOnly + Secure + SameSite flags.
- SPA (frontend without a server): Again Authorization Code + PKCE — but putting the token in localStorage is laying out an open buffet for XSS. Our preference is the BFF (backend-for-frontend) pattern: the token never reaches the browser.
- Mobile application: Authorization Code + PKCE, through the system browser — not an embedded WebView. Tokens are stored in the Keychain/Keystore.
- Server to server: Client Credentials. If there's no user involved, there's no user flow; it's that simple.

There's one more scenario that doesn't fit the table: devices without a keyboard or browser — TV apps, IoT dashboards, command-line tools. The Device Authorization Flow was designed for these: the device shows you a short code, and you go to an address on your phone and approve the code. Years ago we used exactly this pattern on a project where we built a smart TV app; compared with making users type a password with a remote control, it's both more secure and incomparably more comfortable.
Let me underline the WebView warning in the mobile item, because we still run into it a lot in the field. Opening the login screen in the app's own WebView is wrong for two reasons: first, the app can see inside that WebView — including the password the user types for the identity provider. Second, identity providers detect this and block it. The system browser (ASWebAuthenticationSession on iOS, Custom Tabs on Android) is both secure and smoother, since it can pick up the user's existing session.
The three wounds that bleed most in the field
I described the first one at the start: loose redirect URIs. A wildcard registration is the main gateway for token theft; the rule is exact matching. The answer to the objection "but we have staging, test and prod environments" is simple, too: three environments, three separate full URI registrations. A five-minute job. That's how it went in the case from the opening — replacing the wildcard registration with three explicit URIs took half an hour; that was the cost of closing a three-year risk.
The second wound is the immortal token. An access token that never expires, or is valid for 30 days, hands the attacker a 30-day subscription on the day it's stolen. The right setup: short-lived access tokens (on the order of minutes) plus rotating refresh tokens. Rotation means this — every refresh invalidates the old refresh token; when a stolen refresh token is used a second time, the server can detect it and kill the entire session. A stolen token's shelf life should be measured in minutes, not weeks.

The third is what I call "scope obesity." The application asks for access to the user's calendar, contacts and files all at once, "in case we need it later." It both scares the user on the consent screen (it shows up in your conversion rate; we measured it) and multiplies the bill on the day of a potential breach. The principle of least privilege applies in OAuth too: ask for what you need today, and ask for tomorrow's needs tomorrow — incremental authorization exists for exactly this.
Being stingy in the identity layer is the most expensive saving
Beyond these three, there's one more topic that's less well known but surprising when it comes up: logout. Most teams build the login flow meticulously and forget logout. When a user clicks "log out," or their account is compromised, what happens to the access and refresh tokens in circulation? If no token revocation mechanism has been designed, the answer may be "nothing" — the user thinks they've logged out, while the token lives on for a while. Keeping refresh tokens recorded and revocable on the server side is the only solid solution to this scenario. A session's death needs as much design as its birth.
The years boil down to this sentence: the identity layer is the most expensive layer to fix after the fact. You can migrate a database schema, you can version an API; but changing the session mechanism of a hundred thousand users in production is like changing a plane's engine mid-flight. I've experienced many times that a day spent choosing the right flow at the start of a new project is cheaper than a month spent patching the wrong one — both in systems I built from scratch and in ones I stepped into later. The good part: thanks to OAuth 2.1, "right" is no longer open to interpretation; it's written down.
If you're not sure about your current system's OAuth setup, a short review covering everything from your redirect URIs to your token lifetimes usually takes half a day — and it's always cheaper than clearing wreckage. I'm always up for identity-layer conversations; the contact page is right there.