Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying an OpenAPI security handler factory that takes the SecurityRequirement instance #2415

Open
Traderjoe95 opened this issue Apr 12, 2023 · 0 comments

Comments

@Traderjoe95
Copy link

Describe the feature

Allow creating authentication handlers for an OpenAPI security scheme dynamically based on the concrete security requirement. Currently, it is only possible to add a static security handler for a specific feature. It would be nice to be able to derive one from the security requirement, because, as the OpenAPI 3.1 specification states wrt. security requirements:

For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band.

This information is fixed per route and thus a per-scheme factory function could be applied to build the security handler for a specific route.

Use cases

In our use case, we are using role-based JWT authorization and would like to create a handler that combines authentication and authorization in a single step. For this, it would be nice to define the roles required for a specific endpoint already in the OpenAPI specification, which is permitted since version 3.1.

Now, it would be cool to be able to automatically create the required handler based on the OpenAPI specification, e.g.

RouterBuilder builder = ...;

builder.security("roleBasedAuth").handler((SecurityScheme scheme, SecurityRequirement requirement) -> new CombinedHandler(requirement))

Note that, for our use case, the security scheme is not a required argument, although it might be for others, so I am envisioning a signature like so:

public interface Security {
  RouterBuilder handler(BiFunction<SecurityScheme, SecurityRequirement, AuthenticationHandler> factory);
}

Contribution

I am willing to contribute this feature if you think it is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant