-
Notifications
You must be signed in to change notification settings - Fork 602
SECURITY_DEFINITIONS type 'apiKey' isn't compatible with rest_framework.authentication.TokenAuthentication
#660
Comments
Hey @marcgibbons – I did a bit of code-sleuthing and it appears I'd need to shim the keyword in this part of the code into line 1212 (
|
Hi, After upgrading our version of rest swagger for django, we are facing the same problem. We use TokenAuthentication for our API and whatever I put in the "Authorize" button in the UI, it simply doesn't work.
Those are my settings, pretty common ones. Is it a bug or is there a way to make the code work with TokenAuthentication? Currently, all my public APIs endpoints are shown, but none of them requiring authentication. Best, |
Same here. I would be willing to live with the token authorization not working, but the fact that it now hides all the API's that require it prevents me from upgrading to this version of DRF swagger. |
@respondcreate @mwatchi @maxcanada See #662. Need to generate the minified JS before merging, and maybe find a better way because it's an ugly hack IMHO. |
Hey @marcgibbons ! Would you mind taking a look at #662 and see if it's OK to merge? Thanks so much for tackling this @dannywillems !! |
Hey @marcgibbons ! Just wanted to ping you again about this issue, any chance you'd be willing to merge this in order to get token auth working via the swagger interface? |
Hey @marcgibbons ! Were you able to look into this. Has this now been resolved. Unable to use Swagger since the Authorization header needs to be prepended by 'Token'. Thanks in advance. |
Hey @marcgibbons |
Check answer of https://stackoverflow.com/questions/39547208/django-rest-framework-swagger-authentication-error
} In the docs UI when prompt value enter: Provided you authentified before, for example manually with: |
When using
rest_framework.authentication.TokenAuthentication
, a token is validated by being in the Authorization header with a keyword, 'Token ', pre-pending the actual token value. If I use the settings below, the token is added to the Authorization header but it is not prepended by 'Token ':This means entering a valid token in the Swagger Authorize button returns a 401 Unauthorized response since requests are sent like this (note the lack of 'Token ' prepending token value in the 'Authorization' header):
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: a-token-value' 'http://hostname/api/some-endpoint/'
Is it possible to configure
SWAGGER_SETTINGS['SECURITY_DEFINITIONS']
in a way that apiKey/token values are prepended by a keyword (as rest_framework.authentication.TokenAuthentication expects link to relevant code)?NOTE: Token auth (via the swagger interface) worked this way in the 0.3.10 release (here's a link to where it's happening in the codebase. If this is not possible currently, what would it take to implement this? My guess would be two things:
The text was updated successfully, but these errors were encountered: