DEV Community

Sreekar Reddy
Sreekar Reddy

Posted on • Originally published at sreekarreddy.com

πŸ”‘ OAuth Explained Like You're 5

Valet parking with limited keys

Day 6 of 149

πŸ‘‰ Full deep-dive with code examples


The Valet Parking Story

You go to a fancy restaurant. You don't want to find parking yourself.

The valet asks for your car key. But you're worried: what if they open your trunk? What if they steal your expensive sunglasses?

Solution: Valet Key!

A special key that:

  • βœ… Starts the car
  • βœ… Moves it short distance
  • ❌ Can't open trunk
  • ❌ Can't open glove box

OAuth is a valet key for websites!


The Real Problem

You want to use an app that posts to Twitter for you.

Bad way: Give the app your Twitter password 😱

  • They could read all your DMs
  • They could change your password
  • They could do anything!

Good way: OAuth πŸ”

  • App asks Twitter for limited access
  • Twitter asks YOU: "Allow this app to post for you?"
  • You say yes
  • App gets a special "key" (token) that can post within the permissions you approved (as enforced by Twitter)
  • The app doesn't need your password

The Flow

1. App: "I need to post for this user"
     ↓
2. Twitter: "User, do you allow this?"
     ↓
3. You: "Yes, allow posting"
     ↓
4. Twitter β†’ App: "Here's a limited token"
     ↓
5. App uses token to post
Enter fullscreen mode Exit fullscreen mode

In One Sentence

OAuth lets apps access your accounts with limited permissions, without needing your password.

Note: OAuth is mainly for authorization (what an app can do). β€œContinue with Google” typically uses OpenID Connect, which is built on top of OAuth.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

Top comments (0)