florimondmanca / djangorestframework-api-key

🔐 API key permissions for Django REST Framework
https://florimondmanca.github.io/djangorestframework-api-key/
MIT License
678 stars 104 forks source link

401 not authorized if not api_key.is_valid(key): raise self.model.DoesNotExist("Key is not valid.") #162

Closed ulziiburend closed 3 years ago

ulziiburend commented 3 years ago

Recently I've tried to use this library, unfortunately, I've got some difficulties. It gives me 401 error.

my views.py

class LemondRegister(APIView):
    permission_classes = [HasAPIKey,]
    parser_classes = (parsers.MultiPartParser,)

postman request

Screen Shot 2021-03-17 at 10 29 13

I've tried to debug it and got False return for this part of code

        if not api_key.is_valid(key):
            raise self.model.DoesNotExist("Key is not valid.")

Any help?

Desktop

florimondmanca commented 3 years ago

@ulziiburend Heya,

See also #157: you'd need to enter the entire API key which has the form xxx.xxxxxxxx, rather than only the prefix like you did here. The full API key is shown only once in the admin upon creation. :-)

Thanks