Free online courseInteractive · No sign-up · Works offline once loaded
OAuth, OpenID Connect & SAML: single sign-on explained
How “Sign in with …” and company single sign-on really work, from the first redirect to the signed token, and where real attackers got in. With live PKCE, token checks, SAML decoding and DPoP in your browser.
The course as text
Everything from the lessons in 8 short chapters, to read or to look something up later.
Login and permission
Two questions are easy to mix up. Authentication asks: who are you? Authorization asks: what may you do? OpenID Connect and SAML answer the first; OAuth 2.0 answers the second. Single sign-on (SSO) means one identity provider (IdP), for example Microsoft Entra ID, Okta or Google, answers “who are you?” for many applications.
After a login, applications remember you with a session (a cookie in the browser) or with tokens. An OAuth access token is usually a bearer token (RFC 6750): whoever holds it can use it, like cash. That is why tokens are short-lived, travel only over TLS and never belong in logs or URLs.
For companies, SSO is above all about control. When someone joins, moves or leaves, one change in the IdP opens or closes every connected application. With SCIM (RFC 7643/7644) the IdP can even create and delete the user accounts in those applications automatically.
OAuth 2.0
OAuth 2.0 (RFC 6749, 2012) lets an application act on your behalf without ever seeing your password. Four roles: the resource owner (you), the client (the app that wants access), the authorization server (where you sign in and agree) and the resource server (the API with your data). What the client may do is expressed as scopes, and you see them on the consent screen.
The flow for apps with users is the authorization code flow. The client sends your browser to the authorization endpoint with its client_id, a redirect_uri, the scopes, a random state and, today always, a PKCE code_challenge. You sign in and agree. The authorization server sends the browser back to the redirect_uri with a short-lived code. The client exchanges that code at the token endpoint, server to server, for an access token and usually a refresh token. Tokens never travel through the address bar.
Ask for as little as possible: a desk display that shows your next meeting needs read access to the calendar, not to your mail or files. Fewer scopes mean less damage when a token leaks, and a consent screen that people actually understand.
PKCE, tokens and OAuth 2.1
PKCE (RFC 7636, “pixy”) protects the code on its way through the browser. The client makes a random code_verifier (43 to 128 characters), sends only its SHA-256 hash as code_challenge with the first request, and presents the verifier when it redeems the code. Whoever steals the code from a redirect, a log or a malicious app doesn't have the verifier and gets nothing. The OAuth security best practice (RFC 9700, January 2025) recommends PKCE for all clients, and the upcoming OAuth 2.1, still an IETF draft in late 2026, makes it mandatory.
RFC 9700 also says: compare redirect URIs exactly, as strings, and drop the implicit flow and the password grant. Pattern matching on redirect URIs has led to many token leaks: a trailing slash, an extra subdomain or an open redirect parameter is enough.
Access tokens should be short-lived. To stay signed in, clients use a refresh token. With refresh token rotation, every refresh returns a new refresh token and invalidates the old one; if an old one is ever used again, the server assumes theft and revokes the whole chain. For machines without users, the client credentials grant uses the client's own identity, ideally a certificate or workload identity rather than a secret. Devices without a keyboard use the device authorization grant (RFC 8628): the TV shows a code that you enter on your phone. Attackers abuse exactly that: in February 2025 Microsoft described the group Storm-2372 sending fake Teams invitations with a device code; whoever entered it signed the attacker's device in. Block the device code flow where you don't need it.
OpenID Connect
OAuth alone says nothing about who signed in. OpenID Connect (OIDC, 2014, ISO/IEC 26131 since 2024) adds that layer: request the scope openid and you receive an ID token next to the access token. The ID token is a signed JWT for the client, not for an API: iss names the identity provider, sub the user (unique per issuer), aud the client it was issued to, exp and iat the validity, and nonce ties it to the login the client started.
Before trusting an ID token, the client checks (OIDC Core 3.1.3.7): the signature with a key from the provider's JWKS, the issuer, the audience (its own client_id), the expiry and the nonce. Where are the keys? In the discovery document at /.well-known/openid-configuration, which lists the endpoints and the jwks_uri. Keys rotate; the kid in the token header says which one signed. Use a maintained library for all of this; don't parse tokens by hand.
Typical mistakes: accepting any validly signed token without checking aud (so a token for another app works too), allowing alg: none, identifying users by their email address, which can change, instead of iss + sub, and writing tokens into logs. Decode and check tokens of your own with the JWT decoder.
SAML 2.0
SAML 2.0 (OASIS, 2005) is the older single sign-on standard and still the most common one in companies: HR systems, wikis, VPNs and almost every enterprise SaaS speak it. The service provider (SP, the app) and the identity provider (IdP) exchange XML messages through the browser. In the usual SP-initiated flow, the app sends an AuthnRequest to the IdP via the HTTP-Redirect binding (compressed with DEFLATE, Base64-encoded, put in the URL as SAMLRequest). The IdP signs you in and returns a signed Response with an assertion, posted by an auto-submitting form to the app's Assertion Consumer Service (ACS) URL.
The SP must check: the XML signature with the IdP's certificate from the metadata, the issuer, the audience (its own entity ID), the time window (NotBefore/NotOnOrAfter), the recipient (its ACS URL), InResponseTo (matches its request) and that the assertion is used only once. Signature checks in XML are hard to get right. In signature wrapping attacks, an attacker moves the signed element and adds an unsigned one that the application then reads. In March 2025 GitHub Security Lab published two such bypasses in the widely used ruby-saml library (CVE-2025-25291 and CVE-2025-25292, fixed in 1.12.4 and 1.18.0): two XML parsers in the same library saw different documents, so “signature valid” and “this is the user” referred to different elements.
The IdP's token-signing key is the key to every connected app. Whoever steals it can forge assertions for any user, without password or MFA: CyberArk named this Golden SAML in 2017, and the SolarWinds attackers used it in 2020 against on-premises AD FS servers. Keep signing keys in hardware or in a cloud IdP, watch certificate changes, and plan the rollover before a certificate expires.
Microsoft Entra ID
Microsoft Entra ID (until 2023 Azure Active Directory) is the identity provider behind Microsoft 365 and Azure, and for many companies behind everything else too. It speaks OpenID Connect, OAuth 2.0 and SAML. A tenant is one organisation's directory with a tenant ID. An app registration defines an application once (application object, client ID, redirect URIs, certificates and secrets, the API permissions it asks for); an enterprise application is its service principal, the instance in a specific tenant where users are assigned, consent is recorded and SAML or Conditional Access is configured. A multi-tenant app has one app registration and a service principal in every customer tenant.
The endpoints follow one pattern: https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize and …/token, discovery at …/{tenant}/v2.0/.well-known/openid-configuration. Tokens carry tid (tenant), oid (the user's object ID, the same for all apps in the tenant), sub (different for each app), preferred_username (for display only), roles (app roles) and groups. Identify users by tid + oid, never by email: in 2023 the “nOAuth” research by Descope showed that multi-tenant apps matching users by the mutable, unverified email claim could be taken over. Above 200 groups (JWT) or 150 groups (SAML), Entra sends an overage indicator instead of the list, and the app must ask Microsoft Graph.
Conditional Access decides after the first sign-in whether and how access is granted: by user, app, device, location and risk. With authentication strengths a policy can require specific methods; the built-in ones are “Multifactor authentication strength”, “Passwordless MFA strength” and “Phishing-resistant MFA strength” (FIDO2 security keys and passkeys, Windows Hello for Business or platform credential, certificate-based authentication). For admins Microsoft recommends the phishing-resistant strength. Consent decides which permissions apps receive. Since a rollout between mid-July and August 2025, the Microsoft-managed default policy no longer lets users consent to third-party apps reading all files or sites (Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All); application permissions always require an admin. Look at your enterprise applications regularly: which ones have which permissions, and does anyone still need them?
Real attacks and hardening
Most large identity incidents of recent years did not break any cryptography. They abused keys, permissions and validation gaps. In Storm-0558 (2023), a China-based group used a stolen Microsoft consumer signing key from 2016 and a flaw in token validation to forge tokens for Exchange Online; the US Cyber Safety Review Board counted 22 affected organisations and more than 500 people and called the intrusion preventable. In Midnight Blizzard (disclosed January 2024), Russian attackers password-sprayed a legacy test tenant account without MFA, took over an old test OAuth app with high privileges and granted themselves the Exchange Online role full_access_as_app to read Microsoft executives' mailboxes. In Storm-2372 (since August 2024, published February 2025) device codes went out in fake Teams invitations; in April 2026 Microsoft described a campaign that generates the code only at the moment of the click, to get round the 15-minute lifetime.
Sender-constrained tokens limit the damage of stolen tokens. With DPoP (RFC 9449, 2023), the client holds a key pair and signs a short proof for every request: method, URL, time, a unique ID and the hash of the token. The authorization server binds the token to the key's thumbprint (RFC 7638) in the cnf.jkt claim. A thief with the token but without the private key gets nothing. Mutual TLS (RFC 8705) does the same with client certificates.
The hardening list is short: phishing-resistant MFA for every account that can sign in, test tenants included; block flows you don't use (device code, legacy authentication); only admins consent to apps, and someone reviews app permissions; exact redirect URIs and PKCE; validate tokens with maintained libraries and identify users by stable IDs; keep SAML and OIDC libraries current; protect and monitor signing keys; short token lifetimes, refresh-token rotation and sender-constrained tokens where available.
Choosing a protocol and final check
For new applications with users, use OpenID Connect with the authorization code flow and PKCE; for API access, OAuth 2.0. If you sell software to companies, also offer SAML, because many customers' identity teams still connect everything that way, and add SCIM so accounts are created and removed automatically. For machine-to-machine access, use client credentials with certificates or, better, managed identities and workload identity federation, which need no stored secret at all. Old on-premises applications that speak only Kerberos or LDAP can often be published through a proxy such as Microsoft Entra application proxy, so they still get modern sign-in and Conditional Access.
A few passwords remain even with perfect SSO: emergency access accounts (break-glass), which Microsoft recommends keeping as at least two cloud-only accounts with phishing-resistant methods such as FIDO2 keys, excluded from normal Conditional Access policies but closely monitored; secrets for services that can't use managed identities yet; and shared logins of tools without SSO. A team password manager with shared vaults, access logs and secure sharing is the right place for those. Deeper into the building blocks: the Account security course explains passkeys and 2FA from the user's side; the JWT decoder and the PKCE generator let you look at real tokens and challenges.
Words you will meet
- Access token
- Lets a client call an API. Usually a bearer token, short-lived.
- Assertion (SAML)
- A signed XML statement by the IdP: who the user is, until when, for which app.
- Audience (aud)
- The client or API a token was issued for. Anyone else must reject it.
- Authorization code
- A short-lived code in the redirect that the client swaps for tokens.
- Conditional Access
- Rules in Microsoft Entra ID that decide at sign-in whether and how access is granted.
- Consent
- Agreeing that an app may use certain permissions (scopes).
- Device code flow
- Sign-in for devices without a keyboard: a code is entered on another device.
- DPoP
- Binds a token to a key pair of the client; every request carries a signed proof.
- Enterprise application
- The service principal of an app in an Entra ID tenant.
- ID token
- A signed JWT from OpenID Connect that tells the client who signed in.
- IdP
- Identity provider: the service where users sign in, e.g. Entra ID, Okta, Google.
- JWKS
- JSON Web Key Set: the public keys an IdP signs tokens with.
- PKCE
- Proof Key for Code Exchange: ties the authorization code to the client that asked for it.
- Refresh token
- Gets new access tokens without a new login. Rotated with every use.
- SCIM
- Standard for creating and deleting user accounts in apps automatically.
- Scope
- A permission an app asks for, e.g. Calendars.Read.
- Service provider (SP)
- In SAML: the application that relies on the IdP.