Skip to content

Customizing Api-Key name (documentation incorrect) #258

@AxisNL

Description

@AxisNL

Hi,

I have a requirement to change the Api-Key name, but I can't get it to work. I'm not that great of a developer ;)

Running djangorestframework-api-key 2.3.0 for a new project, and getting started with Api keys. I have to support a remote client that needs to send me a header in the format "Authorization: API-KEY ", so I need to change Api-Key to API-KEY.

The documentation however, doesn't seem to work:

from rest_framework_api_key.models import HasAPIKey
from rest_framework_api_key.permissions import BaseHasAPIKey, KeyParser

class BearerKeyParser(KeyParser):
    keyword = "Bearer"

class HasAPIKey(BaseHasAPIKey):
    model = APIKey  # Or a custom model
    key_parser = BearerKeyParser()

As rest_framework_api_key.models does not have a HasAPIKey class for example.

I assume it has to be something like this:

from rest_framework_api_key.models import APIKey
from rest_framework_api_key.permissions import BaseHasAPIKey, KeyParser

class BearerKeyParser(KeyParser):
    keyword = "API-KEY"

class HasAPIKey(BaseHasAPIKey):
    model = APIKey  # Or a custom model
    key_parser = BearerKeyParser()

But if I add the imports to settings.py, I get the error "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.".

I guess I need a bit more handholding ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsRequest for documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions