florimondmanca/djangorestframework-api-key

API_KEY_CUSTOM_HEADER not working

Closed this issue · 2 comments

Describe the bug
API_KEY_CUSTOM_HEADER not working as expected following the guide.

  • putting `API_KEY_CUSTOM_HEADER = "HTTP_X_API_KEY" into settings.py.
  • testing by running
    ❯ curl -X 'GET'
    'http://localhost:8000/test/'
    -H 'accept: application/json'
    -H 'X_API_KEY: xxxxxxxxxx.xxxxxxxxx'

This does not seem to put the headers into request.Meta and I cannot grab the key via request.META["HTTP_X_API_KEY"]

Desktop (please complete the following information):

  • OS: macOs
  • Python Version: 3.10.1
  • Django Version: 4.1.5
  • DRF Version: 3.14.0

Additional context
Add any other context about the problem here.

Ah. It seems DRF/django filter out any header with underscore?
It works if i change the custom header to things like apikey

  1. API_KEY_CUSTOM_HEADER = "HTTP_APIKEY"
  2. expect HTTP_APIKEY in the META
  3. -H 'apikey:xxx`

Should we update the README?

Hi @seed-doordash,

Seeing this just now as I visit the repo again.

Initially you should have been sending a header named X-Api-Key, not X_API_KEY, as indicated in the docs, here: https://florimondmanca.github.io/djangorestframework-api-key/guide/#custom-header

As far as I understand, Django's META contains headers named in all uppercase with - changed to _.

Greetings!