Lesson 07 of 14 · Human and application identity
OAuth 2.0, OIDC, SAML and SCIM
The identity protocols every platform touches, explained by the job each does: OAuth 2.0 for delegated access, OpenID Connect for login, SAML for enterprise single sign-on, and SCIM for provisioning users and groups. Walk through the flows you will meet in portals, CLIs, CI systems and service-to-service calls.
Four protocols, four jobs
| Protocol | Job | Format | Where a platform meets it |
|---|---|---|---|
| OAuth 2.0 | Delegated authorisation: get an access token to call an API | Tokens (often JWTs) | API gateways, service-to-service, CI calling APIs |
| OpenID Connect | Authentication (login) on top of OAuth | ID token (JWT), discovery, JWKS | SSO for portals, kubectl login, workload identity federation |
| SAML 2.0 | Enterprise single sign-on | Signed XML assertions via the browser | Logging in to SaaS with a corporate IdP |
| SCIM 2.0 | Provisioning: create, update, deactivate users and groups | REST + JSON | Keeping app accounts in sync with HR and the IdP |
The school office (identity provider) knows every pupil. OIDC/SAML is the office telling the library "this is Asha" (login). OAuth is Asha getting a permission slip that lets the library app look at her timetable, but nothing else (delegated access). SCIM is the office sending the library its updated class list every morning, so leavers lose their library card automatically.
The roles
- Resource owner: the user who owns the data.
- Client: the app that wants access (a web app, a CLI, a service).
- Authorization server / IdP: issues tokens (Entra ID, Okta, Keycloak, Dex, Google).
- Resource server: the API that accepts tokens.
Tokens you will meet:
- Access token: presented to APIs (
Authorization: Bearer …). Short-lived (minutes). Its audience (aud) names the API. - ID token (OIDC): tells the client who logged in. Not for calling APIs.
- Refresh token: gets new access tokens without another login. Long-lived and sensitive; rotate it on use.
The flows you will see
Authorization Code + PKCE (a user logs in to a web app, SPA, mobile app or CLI):
1. App creates a random code_verifier, sends its hash (code_challenge) with the login redirect:
GET /authorize?client_id=portal&redirect_uri=…&scope=openid profile&code_challenge=…
2. User authenticates at the IdP (password + MFA, or federated SSO)
3. IdP redirects back with a one-time authorization CODE
4. App → POST /token code + code_verifier (the IdP checks the verifier matches the challenge)
5. IdP returns access token (+ ID token, + refresh token)
6. App calls the API with the access token
Client Credentials (service to service, no user): the client authenticates as itself (a secret, a private-key JWT, or a certificate) and gets a token for itself.
Device Code (a CLI or device without a browser): the CLI shows a short code, you approve it on another device, the CLI polls for the token.
Token exchange (RFC 8693): a service swaps an incoming token for a new one for a downstream API. Covered in the next lesson.
Avoid the deprecated Implicit and Resource Owner Password flows: tokens in URLs and apps handling passwords.
Where browser apps keep tokens
Tokens in localStorage can be read by any script injected through XSS. Prefer the backend-for-frontend pattern: the browser holds an HttpOnly, Secure, SameSite cookie, and a small backend holds the tokens.
OIDC under the hood
- Discovery:
/.well-known/openid-configurationlists the endpoints and the JWKS URL with the public keys. - ID token claims:
iss(issuer),sub(stable user ID),aud(the client),exp,iat,nonce, plus profile claims and oftengroups. - The same machinery powers Kubernetes OIDC login (the API server validates ID tokens) and workload identity federation (clouds validate a cluster's ServiceAccount tokens as OIDC tokens).
SAML in one paragraph
The user visits the service provider (SP), is redirected to the IdP, signs in, and the browser POSTs a signed XML assertion back to the SP's Assertion Consumer Service URL. The SP checks the signature against the IdP's certificate, the audience, the validity window and the recipient, then creates a session. Still the most common enterprise SSO protocol for SaaS. The classic bugs are XML signature wrapping and skipped audience or recipient checks, so use a mature library and never hand-roll SAML parsing.
SCIM: the lifecycle half of identity
Login protocols answer "who is this right now?". SCIM answers "should this account exist at all?". The IdP (or an identity governance system) calls the app's SCIM API:
POST /scim/v2/Users joiner: create the account
PATCH /scim/v2/Users/{id} mover: change attributes, group membership
PATCH … "active": false leaver: disable immediately
GET /scim/v2/Groups reconcile groups
Without provisioning, a leaver's SSO is disabled but their local accounts, API keys and tokens in individual apps may live on. Joiner-mover-leaver automation is the core of identity governance.
Try it
Run Keycloak locally (docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak start-dev), create a realm, a confidential client and a user. Fetch the discovery document and JWKS. Get a token with Client Credentials and decode its claims. Then configure kubelogin against it and log in to a kind cluster configured for OIDC.
Recap
- OAuth 2.0 delegates access (access tokens); OIDC adds login (ID tokens, discovery, JWKS); SAML is XML-based enterprise SSO; SCIM provisions and deprovisions accounts.
- Use Authorization Code + PKCE for users, Client Credentials for services, Device Code for CLIs; avoid Implicit and Password flows.
- Keep tokens out of browser storage; use mature libraries for SAML; automate joiner-mover-leaver with SCIM.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.