A. B. Khan

Identity 101 — OAuth2, OIDC, and Tokens

The Mesh Series · Article 6

OAuth 2.0 & OIDCJWT validation.NET & C#Microsoft Entra IDScopes & app roles

Cover: Identity 101

Article 6 · A series on Kubernetes, Istio, C#/.NET, and Microsoft Entra ID — for architects who have to make this work, and then defend it in an audit.

Ask five engineers on your team which OAuth flow their service uses. You will get three shrugs, one confident wrong answer, and one person who actually knows. That last person is the one who has read a token expiry error at 2am. Everyone else has been copying client_id and client_secret between config files and hoping.

That gap — using OAuth every day while not being able to name the flow you are in — is exactly where the security holes live. Not in the crypto. In the assumptions.

So this article is the boring, load-bearing foundation. What OAuth2 actually is. What OIDC adds. The three tokens. The two flows that matter. And the one sentence that decides whether you have authentication or just a comforting string: an unverified token is just a string.

Illustration

Why a BFSI architect should care about a protocol from 2012

Because in a bank, a bearer token is money.

A leaked or unvalidated access token is not an inconvenience. It is an unauthorized transaction waiting to be signed off by your own infrastructure. The token says "I am allowed to call payments.read" and your API believes it, because believing tokens is the whole point. If you never checked who issued that token, or who it was for, or whether it expired an hour ago, then a stolen string just moved money.

Regulators have caught up to this. RBI's IT framework and SAMA's CSF both expect short-lived credentials and real validation of them — not "we integrated with an IdP" but demonstrable, continuous control. SAMA in particular grades you on a maturity model: it is not enough that the control exists, you have to prove it runs. The demo-to-audit gap in identity is precisely this. "We use OAuth" is the demo. "We validate iss, aud, exp, and signature on every request, and here are the logs proving it" is what survives the audit.

There is a second liability hiding in plain sight: the client secret. It is a long-lived bearer password sitting in a config store, and every one of them is a finding waiting to happen. Hold that thought — the passwordless article later in this series is about deleting them entirely with federated credentials. For now, just know that a secret is a cost, not a feature.

How the pieces fit

Two protocols, doing two different jobs. People conflate them constantly.

OAuth2 is authorization. Delegated access. It answers "what is this caller allowed to do." Its entire reason to exist is to hand out tokens instead of passwords so that App A can call API B on your behalf without ever seeing your credentials. "Let this app call that API for me." That is it. OAuth2 does not, by itself, tell you who the user is.

OIDC is authentication, bolted cleanly on top. It answers "who is this user." It reuses all of OAuth2's machinery and adds one thing that matters: the ID token, a signed statement about the user's identity. If someone tells you they "use OAuth to log users in," they mean OIDC, whether they know it or not.

Three tokens fall out of this:

Access token — the one you call APIs with. Short-lived, audience-restricted, carries scopes. This is the bearer credential.ID token — OIDC only. It tells your app who the user is. You do not send it to APIs. You read it, trust it once, and move on.Refresh token — the one that gets you a new access token when the old one expires, without dragging the user back through a login screen. High-value, kept server-side, guarded like a secret.

In this series the responsibility is split three ways, on purpose. The mesh validates the JWT at the edge with Istio RequestAuthentication (a later article). The identity provider — Microsoft Entra ID, the next article — issues the token in the first place. And your C# service validates it again in code, because defense in depth means you do not assume the layer above you did its job. This article is the protocol sitting underneath all three.

The two flows that actually matter

There are more OAuth flows than you need. Implicit is dead. Resource owner password is a fire hazard. Ignore them. Two flows cover the real world.

Authorization Code + PKCE is a user logging in through a browser redirect. The user goes to the IdP, authenticates there (your app never sees the password), and comes back with a code your backend exchanges for tokens. PKCE is the extra proof that stops an intercepted code from being redeemed by an attacker. Every user-facing login — your Angular front end, a mobile app — uses this.

Client Credentials is service-to-service. No user, no browser, no redirect. One service proves which app it is and gets a token. Your accounts-api calling a ledger-api at 3am during batch reconciliation is this flow. There is no human to redirect, so the service authenticates itself — today with a secret, later, ideally, with something that cannot leak.

Show me the token

Here is the service-to-service flow. No user. The accounts-api proves who it is and asks for a token scoped to exactly what it needs.

Code: token

Notice "token_type":"Bearer". That word is the whole security model in five letters. Whoever bears the token may use it. There is no second factor, no "prove you are the caller we issued this to." The token is the proof. Which is why it has to be short-lived (expires_in: 3600 — one hour, and even that is generous for some), scoped to the minimum (payments.read, not payments.*), and validated on arrival.

Now decode that access_token. A JWT is three base64 segments joined by dots: header.payload.signature. The middle segment is the claims — and these are the claims an auditor will ask you about.

Code: jwt

Read the four verifiable claims out loud. iss — did this come from the issuer I trust, or from some other tenant that happens to speak JWT? aud — was this token minted for me, or am I accepting a token meant for a different API entirely (a real, common, exploitable mistake)? exp — is it still alive? sub — who is this, for the audit trail. And the signature, checked against the issuer's public keys, is what stops anyone editing scp from payments.read to payments.write and re-sending it.

Skip any of these and you have not weakened your auth. You have removed it. A JWT you decode but never verify is a self-asserted claim from an anonymous sender. It is a string.

Security · Audit · Integration

When to reach for something else

OAuth2 + OIDC is the default for APIs and service-to-service in a modern mesh. It is not the only tool, and pretending it is will make you fight the wrong battles.

SAML. Older, XML-heavy, verbose, and still the backbone of an enormous amount of enterprise SSO. Pick this instead when you are integrating a legacy IdP or a partner bank's federation that only speaks SAML. You will not enjoy it, but you will ship.Long-lived API keys. Dead simple: one static string, no token dance. Pick this instead when the endpoint is trivial and non-sensitive. Avoid it for anything that touches money or PII — it is a bearer secret that never expires, and it is the first thing an auditor circles in red.Client certificates / mTLS for service-to-service. Pick this instead of client_credentials secrets when both callers live inside the mesh — because the mesh already gives you mutual TLS and cryptographic workload identity for free. No secret to leak, no secret to rotate. This is the earlier half of the series meeting this one.Session cookies. Pick this instead when you are running a classic server-rendered app with a server-side session. For APIs, mobile clients, and service-to-service, tokens win — cookies do not travel well across those boundaries.

From simple to standard

The simple version: OAuth2 hands out tokens instead of passwords so one app can act for you on another. OIDC adds a signed ID token so you also know who the user is. Three tokens — access to call APIs, ID to know the user, refresh to stay logged in. Two flows — Authorization Code + PKCE for humans in a browser, Client Credentials for services. And one rule that separates real auth from theatre: verify signature, iss, aud, and exp on every request, because an unverified token is just a string.

The standard version is what you defend in the audit. Short TTLs you can show. Scopes at least privilege. Validation logged as evidence. Secrets on a path to deletion.

Next up, Article 7: Microsoft Entra ID in plain language — the identity provider that actually implements all of this, issues the tokens you just decoded, and is where you will spend real configuration time. Everything here was the protocol. Next is the product.

Key skills & topics in this article

OAuth 2.0 & OIDCJWT validation.NET & C#Microsoft Entra IDScopes & app roles

  • #Kubernetes
  • #dotnet
  • #Azure
  • #Istio
  • #CloudNative
  • #AKS

Also on LinkedIn.