OAuth 2.0 Scopes and Consent
You'll learn how OAuth 2.0 uses scopes to limit what an application can do on your behalf, and how user consent makes that choice transparent.
What Are OAuth 2.0 Scopes?
When you authorize an app using OAuth 2.0, you're not giving it the keys to your entire account—you're granting specific, limited permissions called scopes. A scope defines what actions the app can perform with the access token it receives.
Think of scopes like hotel keycards: instead of giving a cleaning service a master key to every room, you give them a card that only opens rooms scheduled for cleaning on that day.
Scope Definition and Granularity
Scopes should be:
- Specific:
read:emailis better thanprofile - Granular: Separate
read:messagesfromsend:messages - Descriptive: Names should clearly indicate the permission granted
Example scopes: read:user, write:repo, delete:files
User Consent Flows
When an app requests authorization, the user sees a consent screen listing requested scopes in plain language: "This app wants to read your email and view your profile." The user can approve or deny. This transparency is critical—users must understand what they're authorizing.
Scope Creep Prevention
Scope creep occurs when apps request more permissions than needed. To prevent it:
- Only request scopes your app actually uses
- Request additional scopes later if functionality expands
- Regularly audit which scopes are truly necessary
Least Privilege Principles
Always follow least privilege: request the minimum scopes needed for your app to function. If you only need to read user profiles, don't request write permissions "just in case."
Key Takeaway: OAuth 2.0 scopes enforce least privilege by limiting access tokens to specific, granular permissions, while user consent ensures transparency and control over what applications can access.