florimondmanca/djangorestframework-api-key

Allow for the ability to change the keyword in Authentication Header

brittandeyoung opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
Some Applications have hard coded keywords when accessing an api using an API Key. For example, an application might require the use of the "Bearer " keyword in the Authorization Header.

Describe the solution you'd like
I would like to see the ability to chose a custom Keyword to use in the Authorization header instead of a hard coded value of "Api-Key ". This could be accomplished in the same way the project allows for a custom_header which can be defined in the settings.py file.

example:
A user could provide the preferred custom value in the setting value of API_KEY_CUSTOM_KEYWORD.

Describe alternatives you've considered
I have considered overriding the KeyParser class and the get_from_authorization function inside this class, but it would be much cleaner to provide the ability to simply provide a custom setting.

Additional context
The specific Example I am looking as it the terraform CLI does its api authentication using a Bearer token and cannot be configured otherwise. It would be helpful to be able to configure the application with this custom Keyword instead of having to do class and function override.

Hi @brittandeyoung,

Just to confirm, were you able to make the KeyParser alternative work? Currently that should be supported, as it is designed to allow this kind of use case. How does that look like in code?

Thanks

@florimondmanca Yes, I have made the KeyParser alternative work. Please See the attached pull request. This implements the needed code to allow setting a custom keyword in the Django settings instead of requiring a function override.

The function override version that I am currently using looks exactly like the function code in the pull request.