OAuth 2.0 Flow Overview
You'll learn the authorization code flow in OAuth 2.0 and how it separates authentication (who you are) from authorization (what you can access).
What Is OAuth 2.0?
OAuth 2.0 is a delegation protocol that lets users grant applications limited access to their resources without sharing passwords. Think of it like a hotel key card: the front desk (authorization server) gives you a card (token) that opens your room and the gym, but not other guests' rooms or the safe.
Authorization Code Flow Explained
The most secure OAuth flow works like this:
- User Request: Your app redirects the user to an authorization server (like Google or GitHub)
- User Consent: The user logs in and approves what your app can access
- Authorization Code: The server redirects back to your app with a temporary code (not a token yet!)
- Token Exchange: Your backend exchanges this code + client secret for an access token
- API Access: Your app uses the token to call APIs on the user's behalf
Authentication vs Authorization in OAuth
This is crucial: OAuth 2.0 is primarily an authorization framework, not authentication. It answers "what can this app do?" not "who is this user?" (though extensions like OpenID Connect add authentication).
The separation means:
- Authentication = proving identity (the user logs into Google)
- Authorization = granting permissions (your app gets permission to read their email)
The authorization server authenticates the user, but your app only receives authorization to act on their behalf.
Key Takeaway: OAuth 2.0's authorization code flow keeps secrets secure by never exposing tokens to the browser directly—the code is exchanged server-side, separating user authentication from app authorization.