A Beginner-Friendly Guide to API Authentication & Authorization: Lessons from Real-World APIs
Introduction
So you're building an app, or maybe you're just curious about how apps talk to each other. Either way, you've probably heard terms like "API authentication" and "OAuth" thrown around. And honestly? It can feel pretty overwhelming at first.
I spent some time digging into how GitHub handles authentication, and I want to share what I learned in a way that actually makes sense.
Think of it this way: when you let a third-party app access your GitHub repos, or when you use "Sign in with Google" on some website, there's this whole security choreography💃 happening behind the scenes. Let's break it down.
Authentication vs Authorization: My Bouncer Analogy
I used to mix these up constantly, so let me give you the analogy that finally made it click for me. I got that from a movie where a bouncer bundled out an "unauthorized invitee" 😂
Let's imagine you're going to an exclusive concert:
Authentication is when you show your ticket at the entrance and the bouncer checks and says "Okay, you are who you say you are. Come in."
While authorization is what happens next. If you have a VIP ticket, you get a good spot at the front row to enjoy and see firsthand what is going on, but the general admission ticket doesn't. Same venue but different permissions.
So in API terms:
How GitHub Does Authentication
GitHub supports several ways to authenticate, and each one makes sense for different situations. Let me walk you through them.
1. Personal Access Tokens (PATs)
This is the simplest one to understand. A PAT is basically a really long password that you use instead of your actual password.
Why it's pretty clever:
The downsides:
Instead of typing your password everywhere, create a token once and use that. Safer and smarter.
2. OAuth 2.0 (The Standard Everyone Uses)
You've definitely used OAuth even if you didn't know it. Every time you click "Continue with GitHub" or "Sign in with Google," that's OAuth. Sounds familiar? Now give me a 👍👍👍 before you move on.
Recommended by LinkedIn
Here's the flow (I'll keep it simple):
Why this is brilliant:
The downsides:
OAuth is like giving someone a visitor badge to your house instead of your house keys - they can come in, but only to the rooms you allow, and you can revoke the badge anytime.
What I Learned About Security from GitHub
Least Privilege is Everything
GitHub's token system taught me this: never ask for more permissions than you actually need. When you create a token or OAuth app, you pick specific scopes:
It's tempting to just request admin access to everything, but don't. If your token gets leaked and it only has read access to public repos, the damage is limited. If it has full admin access? That's a disaster.
Keep Authentication and Authorization Separate
Here's something that clicked for me: GitHub doesn't treat "who you are" and "what you can do" as the same thing. OAuth handles proving who you are. Scopes handle what you can do. This separation means:
Layer Your Security
GitHub doesn't just rely on one thing:
Overall, I learned that good security isn't one strong lock, it's many reasonable locks. Did you learn anything new? Comments below!👇
Welcome to Products.Ink—a community for quality product lovers! Subscribe to stay in the loop. 📩 Drop a comment if this resonates with you.
Keep building quality & secure products, Motunrayo Joseph
QA Engineer || Writer, Products.Ink