Automatically infer `OpenApiSecuritySchemes` from authentication configuration
See original GitHub issueAt the moment, when users enable authentication in their ASP.NET apps, they typically have to manually the describe the OpenApiSecuritySchemes
in their application and the top level and configure OpenApiSecurityRequirements
for each route that requires authentication and authorization.
We should infer as much of these definitions as possible so users don’t need to configure auth twice, once for their application and another time for OpenAPI.
Provide metadata support for parts of the specification documented in https://swagger.io/docs/specification/authentication/.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Authentication
OpenAPI 3.0 lets you describe APIs protected using the following security schemes: HTTP authentication schemes (they use the Authorization header):. Basic ...
Read more >Restricting API access with API keys - Cloud Endpoints
This section configures basic authentication with an API key. ... The OpenAPI specification requires an empty list for security schemes that don't use...
Read more >OpenAPI Specification v3.0.3 | Introduction, Definitions, & ...
The OpenAPI Specification allows combining and extending model definitions using the allOf property of JSON Schema, in effect offering model ...
Read more >Spring Boot 3 OpenAPI Documentation with Springdoc
It examines the application at runtime to infer API semantics based on class annotations and configuration beans.
Read more >springdoc-openapi v1.7.0
springdoc-openapi works by examining an application at runtime to infer API semantics based on spring configurations, class structure and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Who knew auth could be so hard? 🤪
I started experimenting with some of this support in the new Microsoft.AspNetCore.OpenAPI package. The problem is generally easy to solve for cookie and JWT bearer-based authentication types, but OAuth authentication types are a lot trickier for us to derive automatic annotations for because:
We’ve had conversations about how to make the authentication system more self-describing for annotation purposes. There’s more design scenarios to reason about here but for .NET 7 we’re scoping it down to auto-generating annotations for JWT-bearer based types to align with the work we’ve done with
dotnet user-jwts
and the options-from-config changes.I spent some time prototyping what this would look like and landed on a pretty solid strategy that uses
PostConfigureOptions
on a customAuthenticationBuilder
that would work well for this.With that in mind, here’s some of the challenges:
PostConfigureOptions
needs to be added to DI as part of theAddAuthentication
call. In my demo, I added this behavior to a customWebApplicationAuthenticationBuilder
that was part ofWebApplication
. Similar to the model that we tried out in .NET 7 withbuilder.Authentication
. It’s not totally necessary but not having it would mean that this behavior will be enabled for all authentication scenarios in .NET 8.PostConfigureOptions
would need to emitOpenApiSecuritySchemes
givenAuthenticationSchemeOptions
but cannot take a dependency on the type since it is not in the shared framework. We could consider packaging it in the shared framework or build a set of intermediary definitions.