TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

โ† Back to OAuth 2.0

๐Ÿ—๏ธ OAuth 2.0: cheat sheet

๐ŸŽจ The analogyA hotel desk gives your helper a key card for one room, for an hour, instead of your master key.
๐ŸŽ“ The regular explanationHow one app gets limited, revocable access to your data in another service without ever seeing your password. An authorization server issues scoped, short-lived access tokens after you approve.
Don't hand over your house keyStep 4 of 4
๐Ÿง’You๐Ÿ–จ๏ธPrint shopphotos.read 1h๐Ÿ›Ž๏ธFront desk๐Ÿ–ผ๏ธ Your photo room
  1. A print shop wants your photos. The old way was to give it your master key. Now it can open every room, forever.
  2. To take that back you'd have to change the locks, which locks out every other helper too.
  3. With OAuth, the print shop sends you to the hotel's front desk instead. You tell the desk, "photos only, please".
  4. The desk gives the print shop a key card that opens only the photo room, and stops working in an hour.
The authorization code flowStep 5 of 5
๐Ÿง’You๐Ÿ–จ๏ธPrint shopverifier kept๐Ÿ›Ž๏ธFront deskconsented๐Ÿ–ผ๏ธ Photo room
  1. The print shop makes up a secret word, keeps it, and sends you to the desk with a scrambled version of it.
  2. At the desk you show who you are and agree to "photos only". The desk never tells the print shop anything about you.
  3. The desk hands you a claim ticket to carry back to the print shop. A ticket on its own opens nothing.
  4. The print shop takes the ticket to the desk, with its secret word. The words match, so it gets the key card.
  5. Now the print shop opens the photo room with its card. Someone who stole the ticket couldn't, without the secret word.
Short cards and renewalsStep 4 of 4
๐Ÿง’You๐Ÿ–จ๏ธPrint shopcard 1h๐Ÿ›Ž๏ธFront deskrevoked๐Ÿ–ผ๏ธ Photo room
  1. The key card works for an hour, so a lost card doesn't do much harm.
  2. After the hour, the room's door beeps red.
  3. The print shop also got a renewal slip. It swaps it at the desk for a fresh card, without bothering you.
  4. You change your mind and tell the desk. The renewal slip is cancelled, and when the card runs out, that's the end.

๐Ÿงฉ Key questions

Why not hand the print shop your master key?
It could open every room, keep a copy, and the only way to stop it is changing every lock. The desk's key card opens one room, for an hour, and can be cancelled.
Why does the desk give you a claim ticket rather than the key card itself?
So the card never travels through your hands, where it could be lost, and only the print shop can swap the ticket. The secret word made up at the start means a grabbed ticket can't be swapped by someone else.
The key card expires after an hour. How does the print shop get a new one without bothering you?
It swaps its renewal slip at the desk. When you change your mind, the desk cancels the slip.