SyntaxPilot
Courses/Cybersecurity Fundamentals/Lesson 33
Video coming soonThis lesson’s video is being made

Start with the notes below; the video appears here as soon as it is on YouTube.

Cybersecurity Fundamentals · Lesson 33 of 90

OpenID Connect, SSO and federation

authentication vs authorization (OAuth vs OIDC)OpenID ConnectID tokennonceUserInfo endpointdiscovery documentsingle sign-on (SSO)federationidentity provider (IdP)service provider (SP)relying partySAML 2.0assertionsXML signature pitfalls (concept)

These are the notes for Cybersecurity Fundamentals (defensive), episode 33. Episode 32's OAuth let an app access your data without your password. Today's question: how does an app learn who you are? That's every "Log in with Google / Microsoft / ..." button. We break a login button, invent OpenID Connect to fix it, and scale it to a whole company: authentication vs authorization, the ID token, nonce, the UserInfo endpoint, the discovery document, single sign-on (SSO), the identity provider (IdP), service provider (SP) and relying party (RP), federation, SAML 2.0 and its assertions, XML signature pitfalls, just-in-time (JIT) provisioning, SCIM and single logout. Every term is explained the first time it appears, and the Glossary at the end defines them all again.

Neha, Kabir, Meera, PrintKaro, QuizMasti, Ravi Photos and every URL, token and ID here are made up, and everything runs locally on toy data. Every code sample runs with Python 3.13 (standard library only); outputs are real, copied from actual runs. The SAML demo is a toy model of the idea (Python dictionaries, not real XML).

The problems you'll solve

Problem Idea it teaches
A login button that accepts any access token Authentication vs authorization; why OAuth alone isn't login
A proof of login made for one app OpenID Connect, ID token, aud, nonce
Getting a name or email after login UserInfo endpoint, profile/email scopes
Finding a provider's endpoints and keys The discovery document
Twelve office apps, twelve passwords Single sign-on, IdP, SP, relying party
Trusting another organisation's logins Federation
Enterprise apps that speak XML SAML 2.0, assertions, signature wrapping
A leaver whose app accounts live on JIT provisioning vs SCIM deprovisioning
Logging out of everything Single logout and its limits

Problem 1: an access token is not proof of login

PrintKaro adds a "Log in with Ravi Photos" button. It runs the OAuth flow from episode 32, gets an access token, asks the photos API "whose token is this?", and logs that person in. But Neha once tried a quiz app, QuizMasti, which also received an access token for her, and QuizMasti's owner still has it.

Demo 1: the obvious login button

# The obvious "Log in with Ravi": treat ANY valid access token as proof of who you are
access_tokens = {"tok-printkaro-11": {"user": "neha",  "client": "printkaro"},
                 "tok-quizmasti-42": {"user": "neha",  "client": "quizmasti"},  # quiz app Neha tried
                 "tok-kabir-07":     {"user": "kabir", "client": "printkaro"}}

def userinfo(token):                            # Ravi Photos API: "whose token is this?"
    rec = access_tokens.get(token)
    return rec["user"] if rec else None

def printkaro_login(token):                     # PrintKaro's login, the obvious way
    user = userinfo(token)
    return f"logged in as {user}" if user else "login failed"

print("Neha via PrintKaro: ", printkaro_login("tok-printkaro-11"))
# QuizMasti's owner keeps Neha's token and pastes it into PrintKaro's login
print("QuizMasti's owner:  ", printkaro_login("tok-quizmasti-42"))

Output:

Neha via PrintKaro:  logged in as neha
QuizMasti's owner:   logged in as neha

QuizMasti's owner now controls Neha's PrintKaro account. Why? An access token says what an app may access. It doesn't say who logged in, when, or for which app, so any app that ever received a token for Neha can log in as her. (This class of bug is sometimes called token substitution, and it has caused real account takeovers.)

Authentication Authorization
Question Who are you? What may you do?
Episodes 28-29 (passwords, MFA, passkeys) 30 (models), 32 (OAuth)
Protocol for apps OpenID Connect OAuth 2.0
Token ID token (for the app) Access token (for the API)

Problem 2: OpenID Connect and the ID token

At an airport OpenID Connect
A lounge pass: lets the holder into a place, whoever they are Access token: for the API
A boarding pass: your name, this flight, accepted only at this airline's gate ID token: for one app, about who logged in
Same airport, same check-in desk, one extra document OIDC is a layer on OAuth 2.0: add the openid scope

OpenID Connect (OIDC) is "an identity layer on top of the OAuth 2.0 protocol" (OpenID Connect Core 1.0, current edition with errata set 2, December 2023). The app adds the scope openid to the authorization request (required), runs the usual authorization code flow with PKCE, and receives an ID token next to the access token. The provider is called the OpenID Provider (OP); the app is the relying party (RP).

The ID token

The ID token is a JWT (episode 31), signed by the provider, with claims about the login:

Claim Meaning Rule
iss Which provider says this Must exactly equal the issuer you configured
sub A stable ID for the user at this provider, never reassigned Use (iss, sub) as the account key, not the email (emails change and can be reused)
aud Who the token is for Must contain your own client_id
exp Expiry Reject on or after it
iat Issued at When it was made
nonce "Number used once": a random value from this login request Must equal the value you sent
auth_time, amr, acr (optional) When and how the user authenticated (e.g. with MFA) Check them if you require MFA

Nonce: before the login, the app makes a random value, stores it in the user's session, and sends it in the authorization request; the provider copies it into the ID token. A replayed old ID token carries an old nonce, so it fails.

Demo 2: validating an ID token

# The fix: an ID TOKEN, a JWT about the login, made FOR one app. (Signature checked as in ep. 31.)
def validate_id_token(c, client_id, expected_nonce, now=1_800_000_000):
    if c["iss"] != "https://login.ravi.example": return "REJECT: wrong issuer (iss)"
    if client_id not in c["aud"]:                return "REJECT: made for another app (aud)"
    if now >= c["exp"]:                          return "REJECT: expired (exp)"
    if c.get("nonce") != expected_nonce:         return "REJECT: nonce mismatch (replay)"
    return f"OK: logged in as {c['sub']}"

base = {"iss": "https://login.ravi.example", "sub": "user-1042", "aud": ["printkaro"],
        "exp": 1_800_000_300, "iat": 1_800_000_000, "nonce": "n-8f31"}
tests = [("Neha's fresh ID token",  base),
         ("token made for QuizMasti", {**base, "aud": ["quizmasti"]}),
         ("an old ID token replayed", {**base, "nonce": "n-0001"})]
for name, claims in tests:
    print(f"{name:25} -> {validate_id_token(claims, 'printkaro', 'n-8f31')}")

Output:

Neha's fresh ID token     -> OK: logged in as user-1042
token made for QuizMasti  -> REJECT: made for another app (aud)
an old ID token replayed  -> REJECT: nonce mismatch (replay)

UserInfo endpoint

Need more than the ID token carries, like a name or an email? Ask for the scopes profile and email (the user consents to them), then send the access token to the provider's UserInfo endpoint, a standard API that returns claims about the logged-in user:

GET /userinfo
Authorization: Bearer <access token>

{"sub": "user-1042", "name": "Neha", "email": "neha@mail.example", "email_verified": true}

Check that the sub from UserInfo equals the sub in the ID token.

The discovery document

Every OpenID Provider publishes its settings at one well-known address: the issuer URL + /.well-known/openid-configuration. It's a JSON discovery document listing the endpoints, the JWKS address (episode 31) and the supported algorithms and scopes.

Demo 3: reading a discovery document

# Discovery: an OpenID provider publishes its settings at ONE well-known address
ISSUER = "https://login.ravi.example"
url = ISSUER + "/.well-known/openid-configuration"
doc = {                                         # what that address returns (toy copy)
    "issuer": "https://login.ravi.example",
    "authorization_endpoint": "https://login.ravi.example/authorize",
    "token_endpoint": "https://login.ravi.example/token",
    "userinfo_endpoint": "https://login.ravi.example/userinfo",
    "jwks_uri": "https://login.ravi.example/.well-known/jwks.json",
    "id_token_signing_alg_values_supported": ["RS256"],
    "scopes_supported": ["openid", "profile", "email"]}

print("fetched:", url)
print("issuer matches:", doc["issuer"] == ISSUER)     # must be exactly the issuer you expect
for key in ["authorization_endpoint", "token_endpoint", "userinfo_endpoint", "jwks_uri"]:
    print(f"  {key:23} {doc[key]}")

Output:

fetched: https://login.ravi.example/.well-known/openid-configuration
issuer matches: True
  authorization_endpoint  https://login.ravi.example/authorize
  token_endpoint          https://login.ravi.example/token
  userinfo_endpoint       https://login.ravi.example/userinfo
  jwks_uri                https://login.ravi.example/.well-known/jwks.json

Configure one issuer URL; a good library finds everything else. Always check that the document's issuer is exactly the one you configured, and prefer a certified OpenID Connect library over hand-written checks.

Problem 3: single sign-on (SSO)

Ravi's company uses twelve apps (mail, HR, payroll, chat, wiki ...). Twelve passwords means reused passwords, sticky notes, twelve places to phish, and when someone leaves, twelve accounts to close (one always forgotten).

Office tower SSO term Meaning
Reception checks your ID once and issues a badge Identity provider (IdP) One system that logs users in (with MFA) and issues tokens or assertions
Each floor trusts the badge Service provider (SP) / relying party (RP) The app that trusts the IdP's statement (SP is SAML's word, RP is OIDC's)
One check opens every floor Single sign-on (SSO) Log in once, use every connected app

Benefits: one strong login, one place for MFA and phishing-resistant passkeys (episode 29), one switch to turn off a leaver, one place to log every login. The catch: the IdP becomes a very valuable target (one login opens everything), so it gets the strongest protection: phishing-resistant MFA for admins, monitoring, and tight control of who can change its settings.

Federation

A library that lets students of a partner college walk in with their own college ID card is federation: one organisation trusting another organisation's logins. In software: a vendor's app trusts your company's IdP, so your staff never get a password there. Federation is set up by exchanging metadata (each side's identifiers, endpoints and signing certificates).

Problem 4: SAML 2.0

SAML (Security Assertion Markup Language) 2.0 was approved as an OASIS Standard in March 2005 and is still everywhere in enterprise software. The flow (the common "SP-initiated" one) looks like OIDC:

  1. Kabir opens the app (SP); it sends his browser to the IdP with an authentication request.
  2. He logs in at the IdP.
  3. The IdP sends the browser back to the SP with a SAML response containing a signed assertion.
  4. The SP checks the signature, the audience, the time limits, and logs him in.

An assertion is the IdP's signed statement in XML: who the user is (NameID), when and how they logged in, which SP it's for (Audience), how long it's valid (NotBefore / NotOnOrAfter), and attributes like email or role.

SAML 2.0 OpenID Connect
Data format XML assertions JSON (JWT ID tokens)
Typical use Enterprise SSO into business apps Consumer "log in with", mobile apps, modern enterprise apps
App is called Service provider (SP) Relying party (RP)
Signature XML Signature over an element JWS over the whole token

XML signature pitfalls (concept)

An XML signature covers one element, pointed to by its ID, not necessarily the whole message. The classic pitfall, signature wrapping, is when an app checks that a valid signature exists, then reads a different, unsigned element that an attacker added. Real bugs of this kind have been found in SAML libraries over the years.

Demo 4: the idea, as a toy

# SAML idea in a toy: the IdP signs ONE assertion; the app must read exactly THAT one
signed_ids = {"a1"}                             # the signature covers the element with ID a1
response = [{"id": "x9", "user": "kabir", "role": "admin"},   # inserted by an attacker
            {"id": "a1", "user": "kabir", "role": "intern"}]  # the real, signed assertion

def careless(resp):                             # "a valid signature exists" ... then reads [0]
    if not signed_ids: return "REJECT"
    a = resp[0]; return f"{a['user']} as {a['role']}"

def strict(resp):                               # use ONLY the element the signature covers
    signed = [a for a in resp if a["id"] in signed_ids]
    if len(signed) != 1 or len(resp) != 1: return "REJECT: unexpected extra assertion"
    a = signed[0]; return f"{a['user']} as {a['role']}"

print("careless app:", careless(response))
print("strict app:  ", strict(response))
print("strict, clean response:", strict([response[1]]))

Output:

careless app: kabir as admin
strict app:   REJECT: unexpected extra assertion
strict, clean response: kabir as intern

Defences: never parse SAML yourself; use a mature, maintained library and keep it patched; process only the element the signature covers; reject responses with unexpected extra assertions; check Audience, Recipient, NotOnOrAfter and that each assertion ID is used once.

Problem 5: provisioning (JIT vs SCIM)

Each app still keeps its own user records. Provisioning = creating accounts and access in each app; deprovisioning = removing them.

  • Just-in-time (JIT) provisioning: the app creates the account the first time someone logs in through SSO, from the token's or assertion's claims. Easy, but the app never hears when someone leaves: an existing app session, an API key or a local password can keep working.
  • SCIM (System for Cross-domain Identity Management, RFC 7644, September 2015): a standard HTTP API (/Users, /Groups) that the IdP calls to create, update and deactivate people in every connected app, so the IdP is the single source of truth.

Demo 5: a leaver, with and without SCIM

# Provisioning: creating and removing accounts in each app. JIT vs SCIM. Toy local app.
app_users = {}

def sso_login(claims):                          # JIT: create the account at first login
    app_users.setdefault(claims["sub"], {"email": claims["email"], "active": True})
    return "welcome, account created"

def app_request(user_id):                       # the app's own 30-day session checks ITS record
    return "200 OK" if app_users[user_id]["active"] else "401 account disabled"

def scim(method, user_id, body):                # SCIM: the IdP pushes changes (RFC 7644)
    if method == "POST":  app_users[user_id] = {**body, "active": True}
    if method == "PATCH": app_users[user_id].update(body)
    return f"{method} /Users/{user_id} -> {app_users[user_id]}"

print("JIT first login:", sso_login({"sub": "kabir", "email": "kabir@ravi.example"}))
# Kabir leaves. The IdP disables him, but with JIT alone the app never hears about it:
print("Kabir's app session:", app_request("kabir"))
print(scim("PATCH", "kabir", {"active": False}))      # SCIM deprovisioning
print("Kabir's app session:", app_request("kabir"))

Output:

JIT first login: welcome, account created
Kabir's app session: 200 OK
PATCH /Users/kabir -> {'email': 'kabir@ravi.example', 'active': False}
Kabir's app session: 401 account disabled

With SCIM, joiners are created on day one, movers updated, and leavers disabled in every connected app within minutes (episode 34 covers the whole joiner-mover-leaver lifecycle).

Problem 6: single logout (SLO)

With SSO there are several sessions: one at the IdP and one in each app. Logging out of one app ends only that app's session, and the IdP would happily log you straight back in.

Single logout (SLO) means the IdP tells every app you used to end its session. SAML defines a single logout protocol, and OpenID Connect has four logout specifications (Session Management, Front-Channel Logout, Back-Channel Logout and RP-Initiated Logout 1.0), final since September 2022. But SLO is best-effort: if an app is offline or the browser is closed, the message can be missed. So don't rely on it alone:

  • keep app sessions short and re-check with the IdP regularly;
  • use refresh tokens the IdP can revoke (episode 31);
  • use SCIM to disable leavers everywhere.

The next problem

One login, with one strong check, now opens every app, and leavers are switched off everywhere. But a company has thousands of joiners, movers and leavers, plus administrators with enormous powers. Who approves access, who reviews it, and who watches the admins? That's enterprise identity: the IAM lifecycle, privileged access management and directories. Episode 34.

The whole chain

  1. An access token used as identity → OpenID Connect.
  2. Proof of login for one app → the ID token: iss, sub, aud, exp, nonce; more details via UserInfo.
  3. Many endpoints and keys → the discovery document.
  4. Twelve passwords → SSO: one IdP, many SPs / relying parties.
  5. Another organisation → federation; enterprise apps → SAML 2.0 assertions (read only what was signed).
  6. Leavers linger → JIT isn't enough: SCIM deprovisioning; and single logout is best-effort.

...and you just invented modern login.

Common mistakes (and what they print)

Mistake What you see Why it's wrong Fix
Access token as proof of login QuizMasti's owner: logged in as neha Access tokens aren't made for one app OIDC ID token; check aud
Skipping the nonce check A replayed ID token is accepted Replay Fresh random nonce per login; compare it
Substring check on aud 'printkaro' in 'printkaro-staging' → True aud may be a single string; in then matches substrings Normalise to a list, then exact match
Reading a claim that isn't there KeyError: 'nonce' A missing nonce must be a rejection, not a crash .get() and reject
Account keyed by email Two people share one account after an email is reused Emails change and get reassigned Key by (iss, sub)
Reading an unsigned SAML element careless app: kabir as admin Signature wrapping Mature library; read only the signed assertion
JIT only, no deprovisioning Kabir's app session: 200 OK The app never hears he left SCIM + short sessions
Trusting single logout alone An offline app keeps its session SLO is best-effort Short sessions, revocable refresh tokens
Not checking the discovery issuer Tokens from a look-alike provider accepted Mix-up between providers Exact issuer match

Mini project: PrintKaro's "Log in with Ravi" handler

The full set of relying-party checks in one function: state (CSRF), a signed ID token with a pinned algorithm (a toy HS256 using the client secret, which OIDC allows for confidential clients; real providers usually use RS256 via the JWKS), iss / aud / exp, nonce, and JIT account creation keyed by (iss, sub), not by email.

# PrintKaro's "Log in with Ravi" handler: state, nonce, signed ID token, iss/aud/exp, account keyed by (iss, sub)
import base64, hashlib, hmac, json, secrets

def b64url(b):   return base64.urlsafe_b64encode(b).rstrip(b"=").decode()
def unb64url(s): return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
ISSUER, CLIENT_ID, CLIENT_SECRET = "https://login.ravi.example", "printkaro", b"pk-secret-91"

def idp_make_id_token(sub, email, aud, nonce, now):            # what Ravi's IdP would send (HS256 toy)
    h = b64url(json.dumps({"alg": "HS256", "typ": "JWT"}).encode())
    p = b64url(json.dumps({"iss": ISSUER, "sub": sub, "aud": [aud], "email": email,
                           "iat": now, "exp": now + 300, "nonce": nonce}).encode())
    return f"{h}.{p}." + b64url(hmac.new(CLIENT_SECRET, f"{h}.{p}".encode(), hashlib.sha256).digest())

accounts = {}                                                  # (iss, sub) -> account
def callback(session, state, id_token, now):
    if state != session["state"]: return "REJECT: state mismatch (CSRF)"
    h, p, s = id_token.split(".")
    if json.loads(unb64url(h))["alg"] != "HS256": return "REJECT: alg"
    if not hmac.compare_digest(unb64url(s), hmac.new(CLIENT_SECRET, f"{h}.{p}".encode(), hashlib.sha256).digest()):
        return "REJECT: bad signature"
    c = json.loads(unb64url(p))
    if c["iss"] != ISSUER or CLIENT_ID not in c["aud"]: return "REJECT: iss/aud"
    if now >= c["exp"]:                    return "REJECT: expired"
    if c["nonce"] != session["nonce"]:     return "REJECT: nonce"
    acct = accounts.setdefault((c["iss"], c["sub"]), {"email": c["email"]})   # JIT, keyed by sub
    return f"OK: account for sub={c['sub']} ({acct['email']})"

T = 1_800_000_000
session = {"state": secrets.token_urlsafe(8), "nonce": secrets.token_urlsafe(8)}
good = idp_make_id_token("user-1042", "neha@mail.example", "printkaro", session["nonce"], T)
print("normal login    :", callback(session, session["state"], good, T + 3))
print("forged callback :", callback(session, "attacker-state", good, T + 3))
print("for QuizMasti   :", callback(session, session["state"],
      idp_make_id_token("user-1042", "neha@mail.example", "quizmasti", session["nonce"], T), T + 3))
print("too late        :", callback(session, session["state"], good, T + 400))
new_email = idp_make_id_token("user-1042", "neha.new@mail.example", "printkaro", session["nonce"], T)
print("email changed   :", callback(session, session["state"], new_email, T + 3), "| accounts:", len(accounts))

Output:

normal login    : OK: account for sub=user-1042 (neha@mail.example)
forged callback : REJECT: state mismatch (CSRF)
for QuizMasti   : REJECT: iss/aud
too late        : REJECT: expired
email changed   : OK: account for sub=user-1042 (neha@mail.example) | accounts: 1

The last line shows why we key accounts by sub: Neha changed her email, but she still lands in the same account (one account in total). A real app would also update the stored email when the provider says it's verified.

Practice

1. An expired ID token. Add a test to Demo 2 whose exp has already passed.

Solution
def validate_id_token(c, client_id, expected_nonce, now=1_800_000_000):
    if c["iss"] != "https://login.ravi.example": return "REJECT: wrong issuer (iss)"
    if client_id not in c["aud"]:                return "REJECT: made for another app (aud)"
    if now >= c["exp"]:                          return "REJECT: expired (exp)"
    if c.get("nonce") != expected_nonce:         return "REJECT: nonce mismatch (replay)"
    return f"OK: logged in as {c['sub']}"
base = {"iss": "https://login.ravi.example", "sub": "user-1042", "aud": ["printkaro"],
        "exp": 1_800_000_300, "iat": 1_800_000_000, "nonce": "n-8f31"}
print("an expired ID token ->", validate_id_token({**base, "exp": 1_799_999_000}, "printkaro", "n-8f31"))
an expired ID token -> REJECT: expired (exp)

2. Make Demo 1 safe. Change PrintKaro's login so it accepts only an ID token whose audience is PrintKaro.

Solution
# Demo 1 made safe: PrintKaro logs people in ONLY from an ID token made for PrintKaro
id_tokens = {"idt-printkaro-11": {"iss": "https://login.ravi.example", "sub": "user-1042", "aud": ["printkaro"]},
             "idt-quizmasti-42": {"iss": "https://login.ravi.example", "sub": "user-1042", "aud": ["quizmasti"]}}
def printkaro_login(id_token):                 # (signature, exp and nonce checks as in demo 2)
    c = id_tokens.get(id_token)
    if c is None or "printkaro" not in c["aud"]: return "login failed: not an ID token for PrintKaro"
    return f"logged in as {c['sub']}"
print("Neha via PrintKaro:", printkaro_login("idt-printkaro-11"))
print("QuizMasti's owner: ", printkaro_login("idt-quizmasti-42"))
print("an access token:   ", printkaro_login("tok-quizmasti-42"))
Neha via PrintKaro: logged in as user-1042
QuizMasti's owner:  login failed: not an ID token for PrintKaro
an access token:    login failed: not an ID token for PrintKaro

3. A SCIM joiner, mover and leaver. Use SCIM to create Meera in finance, move her to sales, then deactivate her.

Solution
app_users = {}
def scim(method, user_id, body):
    if method == "POST":  app_users[user_id] = {**body, "active": True}
    if method == "PATCH": app_users[user_id].update(body)
    return f"{method} /Users/{user_id} -> {app_users[user_id]}"
print(scim("POST", "meera", {"email": "meera@ravi.example", "groups": ["finance"]}))   # joiner, day 1
print(scim("PATCH", "meera", {"groups": ["sales"]}))                                   # mover
print(scim("PATCH", "meera", {"active": False}))                                       # leaver
POST /Users/meera -> {'email': 'meera@ravi.example', 'groups': ['finance'], 'active': True}
PATCH /Users/meera -> {'email': 'meera@ravi.example', 'groups': ['sales'], 'active': True}
PATCH /Users/meera -> {'email': 'meera@ravi.example', 'groups': ['sales'], 'active': False}

4. Name the parts. Your company's staff log into a vendor's expense app with their company account. Which system is the IdP, which is the SP, and what is this arrangement called?

Solution

The company's login system is the IdP; the vendor's expense app is the SP (or relying party). Trusting another organisation's logins is federation, giving staff SSO into the vendor's app.

5. OAuth or OIDC? (a) A calendar app wants to add events to your work calendar. (b) A shopping site wants a "Sign in with Ravi" button. (c) Both.

Solution

(a) OAuth 2.0 (access to an API, scope like calendar:write). (b) OpenID Connect (openid scope, ID token). (c) OIDC: one authorization request with openid plus the API scopes returns both an ID token and an access token.

Quick quiz

QuizMasti got a genuine, signed ID token from Ravi's IdP when Neha logged in there, and sends it to PrintKaro. Which check makes PrintKaro reject it?

  • A: iss
  • B: aud
  • C: exp
  • D: sub
Answer

B, aud. The token is genuine (right issuer, valid signature, not expired, Neha's real sub), but its audience is QuizMasti's client_id, not PrintKaro's. An app must reject any ID token whose aud doesn't contain its own client_id.

Interview questions

  1. OAuth vs OpenID Connect? OAuth 2.0 is for authorization (access tokens for APIs); OIDC adds authentication on top (an ID token about the login, for the app).
  2. Why can't you use an access token to log someone in? It isn't bound to your app or to a login event; any app that got a token for the user could replay it (token substitution).
  3. Which ID token claims must you validate? Signature (pinned algorithm, keys from the JWKS), iss, aud contains your client_id, exp, and nonce; optionally auth_time/acr for MFA requirements.
  4. What is the nonce for? It binds the ID token to the specific authentication request, preventing replay of old ID tokens.
  5. Why key accounts by sub and not email? sub is stable and never reassigned at that issuer; emails change and can be recycled.
  6. What is the discovery document? JSON at /.well-known/openid-configuration listing the issuer, endpoints, JWKS URI and supported features.
  7. Explain IdP, SP and relying party. The IdP authenticates users and issues assertions/tokens; the SP (SAML) or RP (OIDC) is the application that trusts them.
  8. SSO benefits and risks? One strong login, central MFA and offboarding, better logging; risk: the IdP is a single, high-value target and a single point of failure.
  9. What is federation? Trust between organisations, so users of one log into another's services with their home identity.
  10. What is a SAML assertion, and what is XML signature wrapping? A signed XML statement about a user; wrapping attacks make an app read an unsigned element placed next to a validly signed one. Use a mature library.
  11. JIT provisioning vs SCIM? JIT creates accounts at first login but never removes them; SCIM lets the IdP create, update and deactivate accounts in apps through a standard API.
  12. Why is single logout unreliable? It depends on notifying every app; offline apps or closed browsers miss it, so combine it with short sessions and revocation.

Glossary

Term Meaning in plain words Example
Authentication Proving who you are Logging in with a passkey
Authorization Deciding what you may do photos:read
OpenID Connect (OIDC) An identity layer on OAuth 2.0 that tells an app who logged in "Log in with Ravi"
OpenID Provider (OP) The OIDC server that authenticates users login.ravi.example
Relying party (RP) The app that relies on the provider's statement PrintKaro
openid scope The scope that turns an OAuth request into an OIDC login scope=openid email
ID token A signed JWT about the login, made for one app Demo 2
sub The user's stable, never-reused ID at the issuer user-1042
aud The audience: must contain your client_id ["printkaro"]
Nonce A random value from this login request, copied into the ID token n-8f31
Replay Sending an old, captured message again An old ID token
Token substitution Using a token issued to one app to log into another Demo 1
UserInfo endpoint A provider API that returns claims about the logged-in user GET /userinfo
profile / email scopes OIDC scopes for name/profile claims and email Consent screen items
Discovery document JSON listing a provider's endpoints and keys /.well-known/openid-configuration
Well-known URI A standard, predictable path on a website /.well-known/...
JWKS The provider's public signing keys (episode 31) jwks_uri
Session The period you stay logged in, tracked by a cookie or token IdP session, app session
Single sign-on (SSO) Log in once, use many apps Office apps
Identity provider (IdP) The system that authenticates users and vouches for them Company login
Service provider (SP) SAML's word for the app that trusts the IdP Expense app
Federation Trust between organisations' identity systems Partner college's students
Metadata The identifiers, endpoints and certificates two federated parties exchange SAML metadata XML
SAML 2.0 Security Assertion Markup Language; XML-based SSO (OASIS Standard, 2005) Enterprise SSO
Assertion The IdP's signed XML statement about a user NameID, attributes
Attribute A fact about the user carried in an assertion or token role=intern
XML signature A signature over one element of an XML document <ds:Signature>
Signature wrapping Making an app read an unsigned element next to a signed one Demo 4
Provisioning Creating accounts and access in apps Day-one accounts
Deprovisioning Removing or disabling accounts and access A leaver
JIT provisioning Creating the account at first SSO login Demo 5
SCIM System for Cross-domain Identity Management (RFC 7644): a standard API to manage users PATCH /Users/kabir
Joiner-mover-leaver Granting, changing and removing access as people join, move and leave Practice 3
Single logout (SLO) The IdP telling every app to end its session "Log out everywhere"
Best-effort Tries, but doesn't guarantee success SLO
Certified library A library tested against the standard's conformance tests OIDC-certified client

Summary

  • Authentication (who) is not authorization (what). An OAuth access token is not proof of login.
  • OpenID Connect adds the ID token: a signed JWT for one app. Validate the signature, iss, aud (your client_id), exp and the nonce; key accounts by (iss, sub).
  • Get extra claims from the UserInfo endpoint; find endpoints and keys in the discovery document.
  • SSO puts one IdP in front of many SPs / relying parties; federation extends the trust across organisations. Protect the IdP hardest.
  • SAML 2.0 (OASIS Standard, 2005) uses signed XML assertions; beware signature wrapping and never hand-roll SAML.
  • JIT creates accounts but never removes them; SCIM (RFC 7644) lets the IdP deprovision leavers everywhere. Single logout is best-effort.

Next episode: enterprise identity: IAM, the joiner-mover-leaver lifecycle, provisioning and deprovisioning, access reviews, privileged access management (PAM), just-in-time admin access and directories.

Sources: OpenID Foundation, "OpenID Connect Core 1.0 incorporating errata set 2" (15 Dec 2023); OASIS press release on the approval of SAML 2.0 as an OASIS Standard (March 2005); RFC 7644 "System for Cross-domain Identity Management: Protocol" (IETF, September 2015); Mike Jones (self-issued.info, Sept 2022) on the OpenID Connect logout specifications becoming final. Code outputs from Python 3.13. Fetched 5 Nov 2026.