Bitpath

Lesson 1 · Unit 03

Authentication

Keys, cookies and tokens: where they travel, what to check, 401 against 403

13 exercisesabout 3 min

What you practise

  • API keys, sessions and cookies, bearer tokens, the three parts of a JWT decoded, expiry, 401 against 403

Try a question from this lesson

Pick one

Two clients call a reports API. URLs are routinely written to server logs, proxy logs and browser history. Which client handles its credential better?

A  GET /reports?api_key=sk_live_93f2

B  GET /reports
   Authorization: Bearer sk_live_93f2

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Three ways to say who you are

An API key is a long random secret that identifies a program or a project. It lives for months, so it belongs on servers only.

A session cookie identifies a browser: the server looks the session up on every request.

A bearer token is a short-lived credential in the Authorization header. Whoever bears it is let in.

X-API-Key: k_7d1f0c...       API key
Cookie: session=abc123       session
Authorization: Bearer eyJ... token

Concept

Claims an API checks

A JWT is three parts joined by dots: header, payload, signature. The payload is a set of claims, and a server should check more than the signature:

iss: who issued it. aud: which API it is meant for. exp: the Unix time at which it stops being valid. sub: who it is about.

A valid token for another API is not a valid token for yours.

JSON
{
  "iss": "https://login.shop.example",
  "aud": "orders-api",
  "sub": "user-42",
  "exp": 1767225600
}

10 more exercises in the app

  • 1× match the pairs
  • 5× multiple choice
  • 1× fill the blanks
  • 1× type the answer
  • 2× true or false

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy