-
Notifications
You must be signed in to change notification settings - Fork 274
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 to only include ApiKeyAuth
authentication/authorization strategy?
#1094
Comments
ApiKeyAuth
authentication strategy?ApiKeyAuth
authentication/authorization strategy?
I suppose that makes sense because you only add one auth method and are not removing the others. This means you have some endpoints still supporting those auth methods. I usually recommend properly setting DRF's If you just want to hide them without removing them use the whitelist: drf-spectacular/drf_spectacular/settings.py Lines 159 to 163 in 6e48a70
|
Yeah that is a tricky bit — we have additional auth methods for some internal API endpoints, but we don't want to include those in our shared documentation. We're currently filtering to "public" endpoints with a preprocessing hook: SPECTACULAR_SETTINGS = {
"PREPROCESSING_HOOKS": ["path.to.custom_preprocessing_hook"],
} def custom_preprocessing_hook(endpoints):
filtered = []
for path, path_regex, method, callback in endpoints:
# Only include public API paths
if path.startswith("/api/v1/"):
filtered.append((path, path_regex, method, callback))
return filtered You mention:
We have tried using the whitelist, but it doesn't seem to affect anything. Buried in my lengthy original description:
We've tried it with both Is there another way to be doing it, or is this a bug? |
Actually we can generate a filtered schema based on the permission the user has on the API. |
still betting on a different
well If the authenticated schema request would also pass through the
|
Ohhhh my goodness gravy, I deeply appreciate all the time you put into helping me here I went on a long quest to fork drf-spectacular and add some print statements to confirm everything was getting hit correctly with the correct values in our system... And... I found that due to a build/docker issue, not only was my fork change not getting picked up, my original Once I fixed that, and was actually running My apologies for the wild goose chase, thank you again for all your time 🙏 |
Describe the bug
We are only exposing endpoints that use
djangorestframework-api-key
in our generated schemas. We're following the blueprint instructions here to includeApiKeyAuth
.However, we're also seeing
basicAuth
andcookieAuth
in the generated docs, how do we suppress those?Including an empty list for
AUTHENTICATION_WHITELIST
does not seem to affect it.To Reproduce
In
settings.py
:Expected behavior
We would like to only see the
ApiKeyAuth
strategy in generated docsObserved behavior
We also see
basicAuth
andcookieAuth
In Swagger "Authorize":
In Redoc "Authorizations":
In
.yaml
file "securitySchemes":The text was updated successfully, but these errors were encountered: