Back to results for “OAuth)”
.NET › Authentication & Authorization (Identity, JWT, OAuth)

What is the purpose of the 'scope' parameter in OAuth 2.0, and how does it implement the principle of least privilege?

Intermediate

Answer

Scopes are strings representing specific permissions an application requests (e.g., read:profile, write:orders), and the authorization server presents these to the user during consent, issuing an access token limited to exactly those granted scopes. This lets a resource server enforce fine-grained access control -- an application requesting only read:profile can never use its token to write data, even if it were compromised, limiting the blast radius of a leaked token.
// Requesting narrowly scoped access
GET /authorize?client_id=app123&scope=read:profile+read:email&response_type=code

// Resource server checks scope claim before allowing an action
if (!User.HasClaim("scope", "write:orders")) {
    return Results.Forbid();
}
Real-world example A third-party calendar integration requests only the calendar.readonly scope from Google, meaning even if that integration's token were somehow leaked, an attacker couldn't use it to delete or modify the user's calendar events.

Common follow-ups: How do you design a good scope taxonomy for a new API?;What's the difference between scopes and roles/claims?