liveBook · Manning

AddSecurityDefinition

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

AddSecurityDefinition is a Swashbuckle configuration method that registers a security scheme in an OpenAPI document.

AddSecurityDefinition registers an authentication scheme in an OpenAPI document so Swagger UI can describe how callers authorize requests. It defines the scheme; AddSecurityRequirement separately declares which endpoints require it. section 25.5

For JWT bearer authentication, the configuration describes:

  • The security requirement that protects the whole API or selected endpoints. section 25.5

Using the scheme in Swagger UI

After configuration, Swagger UI displays an Authorize button. Enter Bearer <token>, including the space and prefix; subsequent requests carry the token in the Authorization header. section 25.5

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

How deep it goes
Defines a security scheme and distinguishes it from endpoint requirements, without detailing the complete authorization pipeline.
Examples
Uses a JWT Authorization header and Swagger UI's Authorize dialog to attach Bearer tokens.
What it assumes
Assumes familiarity with API authentication, JWT bearer authentication, and basic OpenAPI configuration.
What you can do after
Operate/configure Swagger UI to send bearer-authenticated requests through an OpenAPI security definition.
How it connects
Connects OpenAPI, Swashbuckle, Swagger UI, JWT bearer authentication, and AddSecurityRequirement.

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.