๐๏ธ 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.
- A print shop wants your photos. The old way was to give it your master key. Now it can open every room, forever.
- To take that back you'd have to change the locks, which locks out every other helper too.
- With OAuth, the print shop sends you to the hotel's front desk instead. You tell the desk, "photos only, please".
- The desk gives the print shop a key card that opens only the photo room, and stops working in an hour.
- The print shop makes up a secret word, keeps it, and sends you to the desk with a scrambled version of it.
- At the desk you show who you are and agree to "photos only". The desk never tells the print shop anything about you.
- The desk hands you a claim ticket to carry back to the print shop. A ticket on its own opens nothing.
- The print shop takes the ticket to the desk, with its secret word. The words match, so it gets the key card.
- Now the print shop opens the photo room with its card. Someone who stole the ticket couldn't, without the secret word.
- The key card works for an hour, so a lost card doesn't do much harm.
- After the hour, the room's door beeps red.
- The print shop also got a renewal slip. It swaps it at the desk for a fresh card, without bothering you.
- 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.