OAuth 2.0 Grant Types
What you'll learn: The different OAuth 2.0 flows and when to use each authorization grant type.
Now that you understand OAuth 2.0's roles (client, resource owner, authorization server, resource server), let's explore the grant types—the different recipes for obtaining access tokens based on your application's trust level and capabilities.
The Five Core Grant Types
Authorization Code Grant is the gold standard for web applications with server backends. The user authorizes the app, receives a code, and the server exchanges it for a token behind the scenes. Think of it like getting a claim ticket at coat check—you hand the ticket to staff privately to retrieve your coat.
Implicit Grant (now deprecated) was designed for browser-only apps without backends. It returns tokens directly in the URL fragment. Like receiving your coat check claim ticket as your coat—convenient but exposed. Security risks make this obsolete.
Client Credentials Grant is for machine-to-machine communication where no user is involved. Your backend service authenticates itself directly to get a token. Like a delivery truck using its company credentials to access a warehouse—no individual user needed.
Resource Owner Password Credentials Grant (use sparingly) involves the app collecting the user's username and password directly. Only acceptable for highly trusted first-party apps. It's like giving your house keys to someone instead of having them ring the doorbell—breaks OAuth's delegation model.
Refresh Token Grant lets you exchange a long-lived refresh token for new access tokens without re-authenticating the user. Like having a monthly gym pass that you tap to get daily entry tokens.
Choosing the Right Grant
- Web apps with backends → Authorization Code
- Server-to-server APIs → Client Credentials
- Mobile/SPA apps → Authorization Code with PKCE (modern best practice)
Key Takeaway: OAuth 2.0 provides different grant types for different application architectures—choosing the right flow balances security, user experience, and your app's technical capabilities.