Blog
IAM Chapter 5: OAuth 2.0, Part 1

On this page
- Why SAML Isn't Enough Here
- The Delegation Problem
- The Four Roles
- The Flow: John Connects PartVault to PLM
- Step 5: Entra ID Redirects John's Browser Back
- Step 6: The Browser Delivers It to PartVault
- Access Token as a Hotel Key Card
- Front Channel vs. Back Channel
- What If the Code Is Stolen?
- π΄ CHECKPOINT: Study Notes
Part of the IAM study series.
Also Chapter 4 ended with where SAML breaks: mobile apps, machine-to-machine APIs, and verbose XML. OAuth 2.0 is the fix, and it exists to solve a problem SAML was never built for: delegation β letting another app act on your behalf with limited, revocable access, without sharing your credentials.
Why SAML Isn't Enough Here
SAML (2005) was built for one thing: browser SSO between a human, a browser, and a web app. Three situations sit outside that triangle:
- Mobile app β a native app isn't a browser; logging in means a hacked-together web view, no SSO, no reuse of the real browser's session.
- Server-to-server β no human, no browser, nobody to log in. SAML needs a person to authenticate.
- Third-party access β an outside app needs limited access to John's data, not full impersonation.
The Delegation Problem
Scenario: PartVault, a third-party parts catalogue app, wants to read John's part drawings in PLM β not become John.
The anti-pattern is password sharing: John gives PartVault his PLM username and password directly. That's all-or-nothing β PartVault can do everything John can,
- including delete and export-controlled files
- There's no clean revoke β the only way to cut PartVault off is changing John's own password, which breaks his own logins too
- And the audit trail is useless β PLM's logs show
jwickfor every action, whether it was John at 9am or PartVault's script at 3am; they look identical.
OAuth 2.0 is an open authorization framework (RFC 6749) that lets an app get limited, expiring access to your data through a token, instead of your password. One memory line: SAML answers "who are you?" (authentication). OAuth answers "what may this app do?" (authorization).
The Four Roles
| OAuth role | Plain words | In the PartVault story |
|---|---|---|
| Resource Owner | the user who owns the data | John Wick |
| Client | the app asking for access | PartVault |
| Authorization Server | logs John in, shows consent, issues tokens | Entra ID |
| Resource Server | holds the data, checks the token | PLM's API |
Same Entra ID, two hats. In SAML, its job is to say who John is, so it's the IdP. In OAuth, its job is to hand out permission, so it's the authorization server.
The Flow: John Connects PartVault to PLM
Registration happens once, long before John clicks anything: PartVault is registered with Entra ID and gets a client ID (public) and a client secret (private, stays on PartVault's server). Its redirect URI is on file β the only address an authorization code may be sent back to. PLM's API defines scopes like drawings.read.
- John clicks "Connect to PLM" on PartVault's page.
- PartVault redirects John's browser to Entra ID, carrying
client_id,scope=drawings.read,redirect_uri, andresponse_type=code. Nothing secret is in this address β that's why it's safe to send through the browser. - John logs in at Entra ID with password and MFA, on Entra ID's own page. PartVault never sees the password.
- Entra ID shows the consent screen: "PartVault wants to: read your part drawings" β and makes clear what it can't do (delete, access export-controlled files). John clicks Allow.
- Entra ID redirects back to PartVault's redirect URI with a one-time authorization code β short-lived, single-use.
- PartVault's server calls Entra ID directly, server-to-server, no browser: code + client ID + client secret + redirect URI. John just sees a loading spinner.
- Entra ID verifies all four and replies with an access token (about 1 hour, scoped to
drawings.read) and a refresh token (about 90 days). - PartVault calls PLM's API with the access token attached.
- PLM's API checks the token β signature valid, not expired, scope covers a read β and returns the drawings.
- Later, when the access token expires, PartVault trades the refresh token for a new one. John never knows, until the refresh token itself expires and he has to consent again.
Step 5: Entra ID Redirects John's Browser Back
HTTP/1.1 302 Found
Location: https://partvault.example.com/callback
?code=0.AXEA7fQ2k9_zLkKq3Hn8vQp1sT-gWObX4mNcR2yUeDfLhJ6aAAA.AgABBAIAAAD...
&state=a8F3kQ2xZp91LmN7vB4tR6yW
Step 6: The Browser Delivers It to PartVault
GET /callback?code=0.AXEA7fQ2k9_zLkKq3Hn8vQp1sT-gWObX4mNcR2yUeDfLhJ6aAAA.AgABBAIAAAD...&state=a8F3kQ2xZp91LmN7vB4tR6yW HTTP/1.1
Host: partvault.example.com
This is the address bar John's browser ends up on, and where the malicious extension can read the code. Here is how to explain the two values:
| Value | What it looks like | What it is |
|---|---|---|
code | Long, opaque, unreadable (Entra codes typically start with 0.A) | A one-use claim ticket PartVault swaps for tokens in step 7. It means nothing to anyone who reads it, but it is valid for about 10 minutes. |
state | Short random string, here a8F3kQ2xZp91LmN7vB4tR6yW | A random tag PartVault generated and sent in step 3a. In step 6 PartVault checks that the same value came back. If it doesn't match, PartVault ignores the request, which blocks forged callbacks (CSRF). |
Why the flow is split in two: steps 1β6 go through John's browser β anything the browser carries can leak through history, logs, and extensions, so the only thing that travels there is the authorization code, which is useless on its own. Steps 7β10 happen server-to-server β the client secret, access token, and refresh token never touch the browser.
Access Token as a Hotel Key Card
The analogy that makes the tokens click: an access token is a hotel key card. It carries who approved it, which client, which scope, when it expires, and who issued it β but it is never the passport (John's password), the front desk's authority (MFA), or the booking (session) itself. Whoever holds the card can use it β it's a bearer token, not individually verified against John each time. Stolen, it causes about an hour of damage before it expires.
A refresh token is the booking confirmation β the longer-lived voucher that gets you a new key card without re-showing your passport. Stolen, it can keep minting tokens for much longer, which is why it's sent only over the back channel and never the browser, and why refresh token rotation matters: each use issues a new refresh token and kills the old one, so a replayed old token signals a theft and the whole chain gets revoked.
"When the key card stops working at midnight, John doesn't go back to the airport and re-show his passport. He walks to the front desk, shows the booking confirmation, gets a new card. No passport needed, no re-checking."
Front Channel vs. Back Channel
The front channel is anything the browser carries β visible in history, logs, browser extensions. SAML used only this. The back channel is server-to-server, invisible to the browser, hard to spy on.
| Moment | Route |
|---|---|
| John logs in + consents, code returns | front |
| PartVault swaps the code for tokens | back |
| PartVault calls PLM's API | back |
| Refresh token renews the access token | back |
What If the Code Is Stolen?
The code travels through Johnβs browser (step 5), where a malicious extension could copy it.
Case 1: Web app with a client secret (PartVault)
- The attacker has the code and the client ID, both visible in the address.
- Entra ID also demands the client secret, which lives only on PartVaultβs server.
- The request is rejected. The stolen code alone is useless.
Case 2: app that cannot keep a secret (mobile, desktop, SPA)
- These are public clients. A secret shipped inside the app can be extracted, so they have none.
- The token request is then just code + client_id + redirect_uri, and the attacker has all three.
This protection only exists for confidential clients β ones that can keep a secret, like PartVault's server. A mobile app can't hide a secret, which is why it needs an extra safeguard called PKCE β the next concept, Chapter 4 .
π΄ CHECKPOINT: Study Notes
| Term | One line |
|---|---|
| Delegation | letting another app act on your behalf with limited, revocable access |
| Authorization code | one-time claim ticket, useless without the client secret |
| Client secret | why the code is safe to expose β lives only on the server |
| Access token | the hotel key card β limited key, short-lived, bearer |
| Refresh token | the booking confirmation β gets a new key card without re-showing your passport |
| Front / back channel | browser-visible vs. server-to-server |
β Previous: SAML 2.0 & SSO Β· Back to the series start Β· Next: OAuth 2.0, Part 2 β



