(self, request)
return True
Follows what tastypie does, then tests for IP whitelisting
Follows what tastypie does, then tests for IP whitelisting
Follows what tastypie does then tests for IP whitelisting
def is_authenticated(self, request):
        """Follows what tastypie does, then tests for IP whitelisting
        """
        try:
            username, api_key = self.extract_credentials(request)
        except ValueError:
            return self._unauthorized()

        if not username or not api_key:
            return self._unauthorized()

        User = get_user_model()

        lookup_kwargs = {User.USERNAME_FIELD: username}
        try:
            user = User.objects.prefetch_related("api_keys").get(**lookup_kwargs)
        except (User.DoesNotExist, User.MultipleObjectsReturned):
            return self._unauthorized()

        if not self.check_active(user):
            return False

        # ensure API Key exists
        try:
            key = user.api_keys.get(key=api_key)
        except HQApiKey.DoesNotExist:
            return self._unauthorized()

        # ensure the IP address is in the allowlist, if that exists
        if key.ip_allowlist and (get_ip(request) not in key.ip_allowlist):
            return self._unauthorized()

        request.user = user
        request.api_key = key
        return True
def is_authenticated ( self , request ) : try : username , api_key = self . extract_credentials ( request ) except ValueError : return self . _unauthorized ( ) if not username or not api_key : return self . _unauthorized ( ) User = get_user_model ( ) lookup_kwargs = { User . USERNAME_FIELD : username } try : user = User . objects . prefetch_related ( "api_keys" ) . get ( * * lookup_kwargs ) except ( User . DoesNotExist , User . MultipleObjectsReturned ) : return self . _unauthorized ( ) if not self . check_active ( user ) : return False # ensure API Key exists try : key = user . api_keys . get ( key = api_key ) except HQApiKey . DoesNotExist : return self . _unauthorized ( ) # ensure the IP address is in the allowlist, if that exists if key . ip_allowlist and ( get_ip ( request ) not in key . ip_allowlist ) : return self . _unauthorized ( ) request . user = user request . api_key = key return True