'Copypasted from tastypie, modified to avoid issues with app-loading and
custom user model.'

def is_authenticated(self, request, **kwargs):

    User = get_user_model()
    username_field = User.USERNAME_FIELD
    try:
        (username, api_key) = self.extract_credentials(request)
    except ValueError:
        return self._unauthorized()
    if ((not username) or (not api_key)):
        return self._unauthorized()
    try:
        lookup_kwargs = {username_field: username}
        user = User.objects.get(**lookup_kwargs)
    except (User.DoesNotExist, User.MultipleObjectsReturned):
        return self._unauthorized()
    if (not self.check_active(user)):
        return False
    key_auth_check = self.get_key(user, api_key)
    if (key_auth_check and (not isinstance(key_auth_check, HttpUnauthorized))):
        request.user = user
    return key_auth_check
