Course contentsShow
← Web Development
Lesson 1619 of 2,98229. Web Authentication PatternsFree lesson

OAuth Scopes and Permissions

Requesting specific permissions through scopes and understanding scope-based access control.

OAuth Scopes and Permissions

You'll learn how OAuth scopes let applications request precisely the access they need, creating fine-grained permission control.

What Are OAuth Scopes?

Think of scopes like granting someone a key to specific rooms in your house, not the master key to everything. When an application requests OAuth authorization, it declares which scopes (permissions) it needs—like read:email, write:profile, or access:calendar. The user then sees exactly what they're granting before authorizing.

This is fundamentally different from all-or-nothing access. An app can request read:profile without needing write:profile, limiting potential damage if compromised.

How Scopes Work in the Authorization Flow

During the Authorization Code Flow (from lesson 1617), scopes are included in the initial authorization request:

GET /authorize?
  response_type=code
  &client_id=abc123
  &redirect_uri=https://app.com/callback
  &scope=read:profile read:email

The authorization server shows the user a consent screen: "AppName wants to: Read your profile information, Read your email address." The user approves or denies these specific permissions.

Scope-Based Access Control

Once authorized, the access token contains the approved scopes. Your backend checks these scopes before granting access to protected resources. An API endpoint might require write:posts scope—tokens without it get rejected, even if otherwise valid.

Different scopes create different levels of access with the same authentication mechanism.

Scope Naming Conventions

Common patterns include:

  • Resource:action format (read:profile, write:posts)
  • Hierarchical scopes where admin:users implies read:users
  • Wildcard scopes like user:* for all user-related permissions

Key Takeaway: OAuth scopes enable applications to request only the permissions they need, giving users transparent control over what access they grant and providing granular security through scope-based access control in your APIs.