liveBook · Manning

Security scheme

As explained in The Design of Web APIs, Second Edition

A security scheme is an API security mechanism definition that specifies how a consumer authenticates or authorizes access.

A security scheme defines how an API consumer authenticates or gains authorization. In OpenAPI, schemes live under components.securitySchemes, where each named scheme can organize scopes for access control. section 12.9.1

Define a scheme with a suitable type and flow, then provide required flow URLs such as authorizationUrl. Add scopes as named keys with descriptions; quote names containing colons in YAML. section 12.9.1

Applying scopes to an operation

A security list on POST /beneficiaries can require beneficiary:create or beneficiary:all. The consumer must satisfy one security-list element, using a scope defined by its selected scheme. section 12.9.2

Choose and evolve schemes with the consumer and change impact in mind:

  • Use multiple schemes when scopes need separate groups, such as fine-grained and coarse-grained permissions or consumer-specific permissions. section 12.9.1
  • For webhooks, declare OpenAPI-handled security such as mutual TLS under components.securitySchemes and reference it from the webhook operation. section 14.6.9
  • Treat scheme replacement and scope changes as compatibility work: offer old and new modes temporarily when possible, and review added permissions for breaches. section 15.3
  • Reference schemes by name rather than $ref when building reusable OpenAPI component libraries. section 17.6.1
Figure 12.10 Define scopes in security schemes under components.securitySchemes. You can define multiple security schemes to organize scopes.
figure

Use the figure to inspect how schemes and scopes are organized beneath components.securitySchemes. section 12.9.1

Figure 12.11 The security list contains the security schemes and scopes a consumer needs to use to access an operation.
figure

Use the figure to inspect how an operation declares its acceptable security schemes and scopes. section 12.9.2

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains scheme placement, flows, scopes, operation application, webhook use, reuse limits, and migration risks.
Examples
Uses beneficiary scopes, mutual TLS webhooks, API-key migration, and reusable OpenAPI component libraries.
What it assumes
Assumes OpenAPI structure and operation security lists, while advising security-expert input when scheme types or flows are uncertain.
What you can do after
Build it from scratch by defining schemes and scopes, applying them to operations, and planning safer security migrations.
How it connects
Connects security schemes with scopes, OAuth, mutual TLS, API keys, webhooks, OpenAPI operations, and access control.

Also explained in

Compare how 3 books explain security scheme →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.