liveBook · Manning

Scope

As explained in ASP.NET Core in Action, 3e

A scope is a named permission describing an operation or resource that a client or user has been granted or consented to access.

A scope names access that a client requests when obtaining a bearer token through OAuth 2.0 or OpenID Connect. A user may grant or deny requested scopes, and the identity provider may limit which scopes a client can receive. The resulting access token can contain some—or none—of the scopes requested. section 25.6

A scope does not enforce access by itself. The API decides what the scope means and applies an authorization policy to endpoints that need it. Authentication first validates the bearer token; authorization then checks the endpoint’s requirements against the authenticated user. section 25.6 section 25.2

Require a scope to edit recipes

An API can define a policy that requires the token’s `scope` claim to contain `recipe.edit`, then apply that policy to recipe-editing endpoints. For local testing, `dotnet user-jwts create --scope recipe.edit` adds a scope claim to a generated JWT. Creating the claim does not, on its own, protect an endpoint; the API must require it. section 25.6 section 25.4.2

Figure 25.12 Authorizing a request to a minimal API endpoint. The routing middleware selects an endpoint that is protected by an authorization requirement. The authentication middleware decodes and verifies the bearer token, creating a ClaimsPrincipal, which the authorization middleware uses along with the endpoint metadata to determine whether the request is authorized.
CH25_F12_Lock3

Follow a protected request from endpoint selection through bearer-token validation to the authorization decision. The endpoint’s policy is where a required scope can be checked. section 25.6

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains requests, consent, token contents, and claim-based policies while leaving each scope’s meaning to the API.
Examples
Uses a `recipe.edit` policy for editing endpoints and the `dotnet user-jwts` scope option for test tokens.
What it assumes
Introduces bearer tokens and JWTs before using their claims in API authorization.
What you can do after
Apply it via ASP.NET Core authorization policies to require a token scope on protected API endpoints.
How it connects
Connects OAuth 2.0, OpenID Connect, bearer tokens, JWT claims, and ASP.NET Core authorization policies.

Also explained in

Compare how 9 books explain scope →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.