SECURITY_DEFINITIONS type 'apiKey' isn't compatible with rest_framework.authentication.TokenAuthentication
#660
Description
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 ':
SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'api_key': {
'type': 'apiKey',
'description': 'Personal API Key authorization',
'name': 'Authorization',
'in': 'header',
}
}
}
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:
- Add the ability to add a 'keyword' option to the SECURITY_DEFINITIONS (maybe 'key_prefix' which would default to an empty string) which would then be passed along to the swagger view context.
- Update the javascript to look for this value and prepend a token value with it. Admittedly my javascript skills aren't the best but if you could show me where I would need to shim the code from the afore-linked example in the paragraph into the current codebase I'd be more than willing to do it.