Type something to search...
Secure Authentication & Authorization Exercises

Secure Authentication & Authorization Exercises

Each exercise includes:

  • Scenario
  • Initial Information
  • Problem Statement
  • Tasks for the student
  • Bonus Challenges for deeper thinking

Section 1: OAuth 2.0 + PKCE (for Public Clients)

Exercise 1.1 – SPA Login with PKCE

Scenario: A single-page React app needs to authenticate users using Google OAuth 2.0 and PKCE.

Initial Info:

  • No client secret is used.
  • The React app uses the Authorization Code Flow with PKCE.
  • You control both the SPA and the backend.

Tasks:

  1. Sketch the full flow of OAuth 2 + PKCE: which party does what, in what order?
  2. At each step, identify:
    • What data the client has
    • What data the auth server has
    • What is transmitted between them
  3. Identify the attack vector if PKCE were omitted.
  4. What prevents a malicious attacker from using a stolen authorization code?

Bonus:

  • What happens if someone tries to reuse a code_verifier?
  • Why must the code_verifier be random for each session?

Section 2: OAuth 2.0 – Client Credentials with mTLS or JWT

Exercise 2.1 – Microservice Authorization with JWT Assertion

Scenario: A backend microservice wants to authenticate to an OAuth 2.0 authorization server using a JWT assertion.

Initial Info:

  • The client (service) uses its private key to sign a JWT.
  • The auth server validates the JWT using the public key.
  • No user is involved.

Tasks:

  1. Draw the data flow for:
    • Generating the JWT
    • Requesting the access token
    • Using the token
  2. Define what claims should go in the JWT (e.g. aud, iss, sub, exp).
  3. What would happen if the JWT had a future exp (expiry) date but no nbf (not before)?
  4. How is replay of JWTs prevented?

Bonus:

  • Why is this better than a static API key?

Exercise 2.2 – Client Credentials + mTLS

Scenario: Your OAuth 2.0 client authenticates using mutual TLS.

Initial Info:

  • The client presents a TLS client certificate.
  • The server only issues tokens to known, valid certs.

Tasks:

  1. Map the steps for a successful client credentials + mTLS token request.
  2. How does the server verify the client identity?
  3. What protects this flow from token theft?

Bonus:

  • What does the server store for each client to support mTLS?
  • What are the tradeoffs between mTLS and JWT assertion?

Section 3: WebAuthn / FIDO2

Exercise 3.1 – Passwordless Login with WebAuthn

Scenario: A user wants to log into a web app using their YubiKey or fingerprint scanner.

Initial Info:

  • The app supports WebAuthn.
  • Registration was previously completed.

Tasks:

  1. Step through the authentication flow:
    • Who generates the challenge?
    • What’s stored server-side vs. client-side?
  2. How does the server know it’s talking to the right authenticator?
  3. What prevents phishing or replay attacks?

Bonus:

  • What is “attestation” and when is it useful?
  • How does WebAuthn support multiple devices?

Section 4: JWT Issuance, Refresh, and Revocation

Exercise 4.1 – JWT + Refresh Tokens in a Mobile App

Scenario: A mobile app uses short-lived JWTs and long-lived refresh tokens for authentication.

Initial Info:

  • Access token lifespan: 15 mins.
  • Refresh token lifespan: 30 days.
  • Backend supports rotation and revocation.

Tasks:

  1. Show the steps from:
    • First login
    • Access token use
    • Token refresh
  2. Where are the tokens stored in the client?
  3. What happens if a refresh token is stolen?

Bonus:

  • Implement refresh token rotation: how does it work?
  • How would you detect and respond to reuse of an old refresh token?

Section 5: Threat Modeling & Mixed Auth

Exercise 5.1 – API with 3 Client Types

Scenario: Your API is used by:

  • A SPA frontend
  • A native mobile app
  • A backend microservice

Each needs a different auth flow.

Tasks:

  1. For each client, choose:
    • OAuth flow (PKCE, client credentials, etc.)
    • Token format (JWT, opaque, PoP?)
    • Credential storage method
  2. Create a matrix showing:
    • Who gets what data at each step
    • Who stores what
    • Where revocation and refresh happen

Bonus:

  • Add WebAuthn to the SPA: how does that change the model?
  • Add a CLI tool that needs to login via browser.

Section 6: Proof-of-Possession Tokens (Advanced)

Exercise 6.1 – DPoP Protection

Scenario: A client uses DPoP (OAuth Proof of Possession) to bind tokens to a session.

Initial Info:

  • DPoP involves signing a request with a private key.
  • The server issues a DPoP-bound access token.

Tasks:

  1. Describe what goes into the DPoP JWT header and payload.
  2. Map the flow of:
    • DPoP keypair generation
    • Token request
    • Protected resource access
  3. What happens if the DPoP token is intercepted?
  4. What limits abuse if the token is leaked but not the private key?

Bonus:

  • Why is DPoP better than bearer tokens in public clients?

Related Posts

Horizontal Scaling in Kubernetes

Horizontal Scaling in Kubernetes

Horizontal scaling in Kubernetes refers to dynamically adjusting the number of application instances (pods) based on workload changes to maintain optimal performance. Unlike vertical scaling, which in

read more
How to Use Docker for Development Environments

How to Use Docker for Development Environments

When developing an application running in Docker, you can edit the files on your local machine and have those changes immediately reflected in the running container. This is typically done using Docke

read more
CLI pager commands - more, less, and most

CLI pager commands - more, less, and most

These PAGER commands allow you to navigate through file and data stream content with a variety of useful commands. If you need to manually visually navigate through a lot of text or data, you'll f

read more
Defining New ASCII Designs For Thomas Jensens Boxes Software

Defining New ASCII Designs For Thomas Jensens Boxes Software

The "Boxes" command line tool takes a block of text and wraps it in one of 50 some frames listed with boxed -l and specified by the user with boxes -d the text can either be piped into boxed or a

read more
Javascript ES6 Modules, Introduction

Javascript ES6 Modules, Introduction

With the release of ECMAScript 2015 (ES6), JavaScript introduced a powerful new feature: modules. This addition was a significant shift in how developers structure and manage code, allowing for better

read more
Understanding JavaScript Promises

Understanding JavaScript Promises

In JavaScript, the concept of thenables often arises when working with Promises. Promises inherit from the base class Thenable, meaning that Promises are a type of Thenable, but a Thenable is not

read more
Part 4, Dynamic Imports and Lazy Loading

Part 4, Dynamic Imports and Lazy Loading

Introduction So far, we’ve explored the world of static imports in JavaScript, where dependencies are imported at the start of a script’s execution. However, in modern web development, there are c

read more
Understanding JavaScript Promises and Lazy Loading Callbacks

Understanding JavaScript Promises and Lazy Loading Callbacks

In JavaScript, thenables play a key role in asynchronous programming, particularly with Promises in ES6. One of the advantages of ES6 Promises (which use thenables) over older implementations like

read more
Part 2, Understanding Named and Default Exports

Part 2, Understanding Named and Default Exports

Introduction In the previous part, we introduced the basics of importing and exporting in JavaScript ES6, covering both named and default exports. Now, it’s time to explore these t

read more
Part 1, Getting Started with Modules

Part 1, Getting Started with Modules

Introduction Before ES6, JavaScript did not have a native module system, which made it difficult to split large codebases into manageable pieces. Developers relied on patterns like the Module Patt

read more
Part 3, Re-exports and Module Aggregation

Part 3, Re-exports and Module Aggregation

Introduction As projects grow, the number of modules and dependencies can quickly become overwhelming. In large codebases, managing and organizing these modules is key to maintaining readability a

read more
Managing Multiple Git Identities Per Single User Account

Managing Multiple Git Identities Per Single User Account

If you need to work make changes to code under different identities, there are a few different ways you can approach this. The first solution I saw on many webpages was way too clunky for my taste. It

read more
Never Been a Huge Fan of IDEs, but I Like Visual Studio Code

Never Been a Huge Fan of IDEs, but I Like Visual Studio Code

To be completely honest, for the past many years, I've debated whether or not to use an IDE. On one had, they provide a number of features like code completion, debugging, and a number of other things

read more
Powerful Text Selection Operations in VSCode

Powerful Text Selection Operations in VSCode

VSCode has become one of the most popular IDEs in recent years. It is also available for free. Here are a few text selection options of which you may not be aware. Multiple Selections It is possi

read more
Visual Studio Code - Creating a Custom Text Filter Extension

Visual Studio Code - Creating a Custom Text Filter Extension

In this post I will describe a way to create an extension which allows the user to receive the selected text as a string passed into a Typescript function, run that string through any command line pro

read more
What is Docker and Where and Why Should You Use it?

What is Docker and Where and Why Should You Use it?

Docker is a platform designed for containerization, allowing developers to package applications and their dependencies into lightweight, portable containers. These containers are isolated environments

read more
What is Kubernetes? Where and Why Should You Use it?

What is Kubernetes? Where and Why Should You Use it?

Key Use Cases and Benefits Kubernetes simplifies the deployment and scaling of applications through automation. It facilitates automated rollouts and rollbacks, ensuring seamless updates without d

read more
Secrets Management DevOps Tools and More

Secrets Management DevOps Tools and More

These tools provide a means of securely storing secrets (encryption keys, passwords, all that good stuff that you want to make available to your production systems, but you must protect from exposure)

read more
Web Application Boilerplate

Web Application Boilerplate

I've been tinkering with a number of projects and along the way I've come up with what I think is a solid starting point for any web application that you might build. Understanding that your applicat

read more
Part 5, Best Practices and Advanced Techniques

Part 5, Best Practices and Advanced Techniques

In the previous parts of this series, we explored the fundamentals of module importing and exporting in ES6, the different ways to define modules, and how to work with default and named exports. In th

read more
Using Makefiles, SOPS, and virtualenv Together for Elegant Python Environments

Using Makefiles, SOPS, and virtualenv Together for Elegant Python Environments

I've been managing my secrets with sops ever since I looked into the subject last month, and I've been using Makefiles to handle bringing up my docker environments as they provide a nice way to not

read more