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

Global security scheme not added to path.security section #48

Closed
foarsitter opened this issue May 1, 2020 · 3 comments
Closed

Global security scheme not added to path.security section #48

foarsitter opened this issue May 1, 2020 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@foarsitter
Copy link
Contributor

When using the SECURITY setting, the defined security schemes are added at the global level.

This go's well when you do not have other authentication_classes defined. When you do have authentication_classes defined, the global defined security schemes are not added to the path.security section and thus not available for the endpoints.

My current solution is to override AuthSchema.get_auth and return None when settings.DEFAULT_AUTHENTICATION_CLASSES equals view.authentication_classes

class SettingSecureAutoSchema(AutoSchema):

    def get_auth(self):

        if api_settings.DEFAULT_AUTHENTICATION_CLASSES == self.view.authentication_classes:
            return None

        return super().get_auth()

An other solution is to add everything that is in SECURE to the path.security section.

Is this the direction you want to go? Are should we introduce a list in settings where we can add extra OpenApiAuthenticationExtension classes?

@tfranzel
Copy link
Owner

tfranzel commented May 1, 2020

this was not thoroughly tested because it was more like a fallback. it should receive a fix.

OpenApiAuthenticationExtension does not have to be added anywhere. put it anywhere in your code so that the interperter comes by at least once. it autoregisters and is used automatically.

however, if you want to use it for djangorestframework-api-key, there is a fix required because it behaves slightly different.

this all should be better documented, sry

@tfranzel tfranzel added bug Something isn't working enhancement New feature or request labels May 1, 2020
@tfranzel
Copy link
Owner

added explicit deprecation warning for SECURITY (6f2c447). OpenApiAuthenticationExtension should be the default way to go.

@tfranzel
Copy link
Owner

in case you do use djangorestframework-api-key this fix should accommodate you. security is now added everywhere if provided. OpenApiAuthenticationExtension is of course still preferred everywhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants