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

Provide custom SecurityScheme for a specific endpoint #2

Open
nikto-b opened this issue Mar 31, 2024 · 3 comments
Open

Provide custom SecurityScheme for a specific endpoint #2

nikto-b opened this issue Mar 31, 2024 · 3 comments

Comments

@nikto-b
Copy link

nikto-b commented Mar 31, 2024

Is there any way to provide SecurityScheme to a specific API endpoint? Looks like its only used in a global options and there is no way to provide custom auth for a single endpoint even with custom header because ParameterLocation.Header is not used anywhere

@hunyadi
Copy link
Owner

hunyadi commented Mar 31, 2024

There is limited support for overriding the default security scheme. The decorator @webmethod takes a Boolean parameter called public, which can make an endpoint publicly accessible, requiring no prior authentication. This is one of the last examples in the sample code:

class Endpoint(JobManagement, PeopleCatalog, Protocol):
    @webmethod(route="/auth", public=True)
    def do_authenticate(self, credentials: Credentials) -> TokenProperties:
        ...

Other than this bare-bone support for disabling authentication, I don't think the library exposes any per-endpoint override capabilities. If there is support for this in OpenAPI, integrating this feature would likely require extending @webmethod with new arguments to pass the per-endpoint security scheme.

@nikto-b
Copy link
Author

nikto-b commented Mar 31, 2024

Looks like OpenAPI 3.0.0 provides security requirement for a specific operation

Anyway, is there any way to provide header option in a request schema? Greping whole library sources gives no results
kinda so:

@dataclass
class AuthSchema:
    x_token: Annotated[str, ParameterLocation.Header]

@hunyadi
Copy link
Owner

hunyadi commented Mar 31, 2024

You would want to create a SecuritySchemeAPI object (meant for specifying authentication via an API key) and use its in_ parameter to set one of the ParameterLocation enumeration values. ParameterLocation is defined in specification.py.

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

No branches or pull requests

2 participants