-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respond with 401 for requests with bad credentials (#4126)
* Respond with 401 for requests with bad credentials * Try fixing documentation errors * Fix schema test failures
- Loading branch information
1 parent
a85356b
commit 575f529
Showing
11 changed files
with
183 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,3 @@ | |
"rate_limit_model": "enhanced", | ||
} | ||
} | ||
|
||
auth_key_info_403_example = {"application/json": "Forbidden"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from rest_framework.exceptions import AuthenticationFailed | ||
|
||
from drf_spectacular.authentication import TokenScheme | ||
from oauth2_provider.contrib.rest_framework import ( | ||
OAuth2Authentication as BaseOAuth2Authentication, | ||
) | ||
|
||
|
||
class OAuth2Authentication(BaseOAuth2Authentication): | ||
# Required by schema extension | ||
keyword = "Bearer" | ||
|
||
def authenticate(self, request): | ||
result = super().authenticate(request) | ||
if getattr(request, "oauth2_error", None): | ||
# oauth2_error is only defined on requests that had errors | ||
# it will be undefined or empty for anonymous requests and | ||
# requests with valid credentials | ||
# `request` is mutated by `super().authenticate` | ||
raise AuthenticationFailed() | ||
|
||
return result | ||
|
||
|
||
class OAuth2OpenApiAuthenticationExtension(TokenScheme): | ||
target_class = "conf.oauth2_extensions.OAuth2Authentication" | ||
name = "Openverse API Token" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.