Course contentsShow
← Software Engineering
Lesson 1022 of 1,93331. Authentication and AuthorizationFree lesson

OAuth2 Scopes and Consent

Designing granular permissions with scopes and implementing user consent flows.

OAuth2 Scopes and Consent

You'll learn how to define granular permissions using OAuth2 scopes and implement user consent flows to protect user data.

What Are OAuth2 Scopes?

Scopes are permission labels that define exactly what an access token is allowed to do. Instead of granting an application complete access to a user's account, scopes let you request only the specific permissions you need.

Think of scopes like keys to different rooms in a building. An employee might have a key to their office and the break room, but not the server room. Similarly, a third-party calendar app might have the read:calendar scope but not delete:email.

Designing Granular Scopes

Good scope design follows the principle of least privilege:

  • Read vs Write: Separate read:profile from write:profile
  • Resource-based: orders:read, orders:create, orders:delete
  • Hierarchical: admin:all might imply all other scopes
  • Descriptive: Use clear names like photos:upload not just photos

Common scope examples: openid, profile, email, read:posts, write:messages

The User Consent Flow

When an application requests scopes, the authorization server presents a consent screen to the user. This screen explains what permissions are being requested in human-readable language:

  1. Application redirects user to authorization server with requested scopes
  2. User sees: "AppName wants to: View your profile, Read your calendar"
  3. User clicks "Allow" or "Deny"
  4. If allowed, the issued access token is limited to those approved scopes

The consent flow ensures users make informed decisions about data sharing—they're not blindly trusting applications.

Key Takeaway: OAuth2 scopes enable fine-grained access control by defining specific permissions, while consent flows ensure users explicitly authorize what data third-party applications can access, implementing both security and user transparency.