Backend Developer · Focus area 3: Security and sign-in
BE5: Sign-in with OAuth 2 and OpenID Connect
Goal: understand and use the standard sign-in protocols: tell sign-in from permission, follow the authorization code flow with PKCE, know what ID tokens and access tokens are for, check access tokens properly in an API, and handle refresh, sign-out and machine-to-machine access.
You'll need: Module 44 (authentication) and Module 74 (authentication and authorisation), BE1, and the TiffinBox kit with the
practice sign-in server running (npm run sim).
Where this is used: "Sign in with Google", a bank app's login, a company's single sign-on to dozens of internal tools, and one service calling another. Nearly every modern app hands sign-in to an identity provider through OAuth 2 and OpenID Connect.
How it differs: a cybersecurity specialist tests and attacks sign-in systems. A backend developer builds the API side: accepting only valid tokens, for the right API, with the right permissions, and doing it with well-tested libraries instead of home-made code.
Time: reading about 2 hours · practice (the Try it tasks) about 3 hours · assignment about 3 to 4 hours.
Lessons
- 1Who you are, and what you may doReading 15–25 minutes, plus practice✓
- 2The authorization code flow with PKCEReading 15–25 minutes, plus practice✓
- 3ID tokens, access tokens and scopesReading 15–25 minutes, plus practice✓
- 4Checking access tokens in an APIReading 15–25 minutes, plus practice✓
- 5Refresh, sign-out and machine accessReading 15–25 minutes, plus practice✓
🛠️Assignment: Sign-in for TiffinBox
This completes the sign-in part of Project 1.
- Draw the authorization code flow with PKCE for
tiffin-web, labelling each request, parameter and token. - Decode an access token and an ID token from the kit and explain every claim.
- Rebuild
api/auth.jsto verify tokens with the JWKS (signature, algorithm, issuer, audience, expiry) and check scopes. - Show refresh token rotation and a client credentials token in action.
- Write the token lifetimes and revocation plan you'd recommend for TiffinBox's app, tablets and services.
Self-check before you finish:
- [ ] Your API never reads claims from an unverified token.
- [ ] Wrong audience, wrong issuer, forged signature and expired tokens all get
401; missing scope gets403. - [ ] Tokens appear only in headers, never in URLs or logs.
- [ ] Access tokens are short-lived, and refresh tokens rotate.
- [ ] Machine clients use their own credentials and scopes.
✅Module check
Explain in a few sentences, in your own words:
How does an API know a request comes from a signed-in user with permission, using OAuth 2 and OpenID Connect?
Show a good answer
A good answer mentions: authentication versus authorisation, and an identity provider instead of home-made passwords; the authorization
code flow with PKCE, exact redirect URIs and state; ID tokens for the client (aud = client ID) versus access tokens for the API (aud =
API), scopes as permissions, and JWT payloads being readable by anyone; verifying every token with a library against the IdP's JWKS, with
fixed algorithms and checks of issuer, audience and expiry, then scopes, returning 401 or 403; and short-lived access tokens, rotating
refresh tokens, revocation, and client credentials for machines.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
