liveBook · Manning

Scope-based authorization policy

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

A scope-based authorization policy is an authorization policy that requires an access token to contain a specified scope.

A scope-based authorization policy permits an API operation only when the bearer access token contains a required scope. The API defines what each scope means and applies the policy to protected endpoints. section 25.6

Use scopes to express API access boundaries:

  • Require a recipe.edit scope on endpoints that edit recipes. section 25.6
  • Require an application-wide scope such as recipeApi, which can sometimes replace audience validation. section 25.6
  • Remember that scopes have no inherent behavior; the API must connect them to authorization policies. section 25.6

Recipe editing policy

Register a policy such as RecipeEditScope with RequireClaim("scope", "recipe.edit"), then apply it to the minimal API endpoints that edit recipes. section 25.6

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

Trace how routing selects a protected endpoint, authentication verifies the bearer token and creates a ClaimsPrincipal, and authorization evaluates the endpoint requirement. section 25.6

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

How deep it goes
Defines scope semantics, shows policy registration, and discusses endpoint application and audience-validation alternatives.
Examples
Uses recipe.edit, recipeApi, and protected minimal API endpoints as concrete scope examples.
What it assumes
Assumes familiarity with bearer tokens, identity providers, requested scopes, and granted scopes.
What you can do after
Apply it via ASP.NET Core authorization policies to restrict minimal API endpoints by token scope.
How it connects
Connects bearer tokens, OAuth 2.0, OpenID Connect, claims, authentication, and authorization policies.

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.