Advanced

Authentication in front of a Flask app

The app does not know who the user is until something says so. The something is a decision about who decides, and the decision is a component with a boundary.

What you will see

One line with two dates. A rotation with a next date is a rotation that will happen.

About 1 min of reading

Try It

Refuse a forged claim

1

Write the two claims

printf 'signed yes\nforged no\n' > /tmp/c.txt; grep yes /tmp/c.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
signed yes. Only the signed claim is accepted, and the word is the check.
2

Attempt the forged one

printf 'forged\n' | awk '{print ($1=="signed") ? "accept" : "refuse"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
refuse. The refusal is a 401, and the 401 is the boundary speaking.
3

Write the rotation date

printf 'secret rotated=2026-10-01 next=2027-04-01\n' > /tmp/r.txt; cat /tmp/r.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line with two dates. A rotation with a next date is a rotation that will happen.

Data Flow

A cookie to a decision
1 The cookie arrives as text
↓
2 The signature is checked against the secret
↓
3 The claim is accepted or refused
↓
4 The decision is written with the reason
Why this works
Why the secret is rotated

A secret that is old is a secret that signs for years. A rotation is a decision about how long a claim may live.

The one test that must exist

A forged claim is refused. The test is the whole proof, and the proof is in the suite.

Examples

A session cookie is a claim

It says who the user is. The claim is only true if the app signed it, and the signature is the thing that makes it true.

The secret is the signer

Without a secret the claim is unsigned. An unsigned claim is a claim anyone can write.

The check is at the boundary

The check happens before the handler runs. A check inside the handler is a check the handler can skip.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Layers between the app and the client
Previous Lesson
Layers between the app and the client
Next Lesson
Forms and redirects
Forms and redirects →