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

How do we disable an authentication scheme? #326

Closed
tiholic opened this issue Mar 7, 2021 · 4 comments
Closed

How do we disable an authentication scheme? #326

tiholic opened this issue Mar 7, 2021 · 4 comments
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@tiholic
Copy link

tiholic commented Mar 7, 2021

I want to disable Session authentication scheme from schema and shown only Token Authentication

@tfranzel
Copy link
Owner

this is currently not supported

@drien
Copy link

drien commented May 18, 2021

For anyone coming through here, I had a need for this (an API with auth classes used only by internal clients and not relevant to external consumers) and hacked together a basic solution by subclassing drf_spectacular.openapi.AutoSchema and overriding the get_auth() method with a small change.

This library has been much better than the other drf openapi tools I've used in the past...if this is functionality you'd ever consider making part of the core library I'd be happy to work up a PR with tests/docs/etc.

from drf_spectacular.openapi import * # noqa


class EnumeratedAuthOnlyAutoSchema(AutoSchema):

    def get_auth(self):
        """
        Copy-pasted from parent class with a small change to allow enumerating the specific authentication classes we want to
        expose to users rather than everything we actually have enabled in the django rest framework config.
        """
        allowed_auths = set(settings.SPECTACULAR_SETTINGS.get('ALLOWED_AUTH_CLASSES', []))

        auths = []
        for authenticator in self.view.get_authenticators():
            if f'{authenticator.__module__}.{authenticator.__class__.__name__}' not in allowed_auths:
                continue
        ...

@tfranzel tfranzel added enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending labels Jul 29, 2021
@tfranzel
Copy link
Owner

this is now supported 😄

@drien
Copy link

drien commented Jul 29, 2021

🎉 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

3 participants