Lesson 1 · Unit 03
Authentication
Sessions, tokens and second factors: proving who you are
What you practise
- Passwords, sessions and cookies vs tokens, what a JWT contains and what it must not, expiry and refresh, MFA, OAuth as "sign in with" in outline
Try a question from this lesson
Pick one
HTTP is stateless: every request arrives with no memory of the last. You log in once, then open ten pages. How does the server know requests 2 to 10 are yours?
Correct answer
Login set a cookie with a random session id, resent each time
Why
The login response sets a cookie, and the browser returns it with every later request. An IP address is shared by whole offices and changes on mobile, and resending the password would expose it ten times as often.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Sessions
A session is a row on the server: a long random id, the user it belongs to, an expiry.
The cookie holds only the id. Everything else stays on the server, so logging out, or kicking out a thief, is just deleting the row.
Whoever holds the id is that user until it expires. Treat it like a temporary password.
cookie: sid=9f2c...
server: 9f2c... -> user 42, until 18:00Concept
Tokens: the JWT
A JWT is a signed token in three parts joined by dots: header.payload.signature.
The payload is base64-encoded JSON holding claims such as sub (who) and exp (when it expires). The server signs it with a key and later only checks the signature: no session table is needed.
Encoded is not encrypted. Anyone holding the token can read it.
eyJhbGciOiJIUzI1NiJ9 header
.eyJzdWIiOiI0MiJ9 payload
.4f9a... signature10 more exercises in the app
- 5× multiple choice
- 1× fill the blanks
- 1× true or false
- 1× type the answer
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.