AddSecurityRequirement declares which authentication scheme an API or its operations require in the OpenAPI document. Paired with AddSecurityDefinition(), it tells Swagger UI that the API is protected. section 25.5
Configure bearer authentication in a small Swashbuckle setup:
- Define the bearer security scheme with AddSecurityDefinition(). section 25.5
- Apply AddSecurityRequirement() to declare that the whole API is protected; configure it conditionally when anonymous endpoints are needed. section 25.5
Authorize requests in Swagger UI
After the requirement is configured, Swagger UI displays an Authorize button. Enter Bearer <token>, including the space and prefix. Swagger UI saves the value and attaches it to subsequent requests in the Authorization header. section 25.5
