Closed mathijsfr closed 2 years ago
Describe the bug When trying to validate my api key, get_usable_keys() returns empty. This results in not being able to validate my api key.
To Reproduce
class UserAPIKey(AbstractAPIKey): user = models.ForeignKey( User, on_delete=models.CASCADE, related_name="api_keys", ) subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE)
permission_classes = (HasAPIKey, )
class ProductSales(generics.RetrieveAPIView): permission_classes = (HasAPIKey, ) def get(self, request, *args, **kwargs): result = 'test' return Response(result)
https://github.com/florimondmanca/djangorestframework-api-key/blob/a9579e358ebfb5ede888f78d3f0af29ac1ee9d6f/src/rest_framework_api_key/models.py#L43
def get_from_key(self, key: str) -> "AbstractAPIKey": prefix, _, _ = key.partition(".") queryset = self.get_usable_keys() print('test', queryset) try: api_key = queryset.get(prefix=prefix) except self.model.DoesNotExist: raise # For the sake of being explicit. if not api_key.is_valid(key): raise self.model.DoesNotExist("Key is not valid.") else: return api_key
Expected behavior Expected to have usable keys to validate my api key
Looks like the usable api keys are requested from rest_framework_api_key_apikey table, instead of the UserApiKey table. How do I solve this?
rest_framework_api_key_apikey
UserApiKey
Desktop (please complete the following information):
Describe the bug When trying to validate my api key, get_usable_keys() returns empty. This results in not being able to validate my api key.
To Reproduce
permission_classes = (HasAPIKey, )
https://github.com/florimondmanca/djangorestframework-api-key/blob/a9579e358ebfb5ede888f78d3f0af29ac1ee9d6f/src/rest_framework_api_key/models.py#L43
Expected behavior Expected to have usable keys to validate my api key
Looks like the usable api keys are requested from
rest_framework_api_key_apikey
table, instead of theUserApiKey
table. How do I solve this?Desktop (please complete the following information):