Ejabberd auth http查询到django服务器未经身份验证

Ejabberd auth http query to django server unauthenticated

我正在尝试使用 ejabberd_auth_http module for user authentication in ejabberd server. Hence, for authentication, ejabberd server (http://localhost:5222) 将查询 django rest 服务器并检查用户是否存在提供的凭据。 django服务器中的GET请求处理程序如下。

@api_view(['GET'])
@permission_classes([AllowAny])
def user_exists(request):
    try:
        User.objects.get(username=request.query_params.get("user"))
        return Response({"user_exists": True})
    except User.DoesNotExist:
        raise exceptions.NotFound(False)


@api_view(['GET'])
@permission_classes([AllowAny])
def check_password(request):
    try:
        User.objects.get(Q(......))
        return Response({"check_password": True})
    except User.DoesNotExist:
        raise exceptions.AuthenticationFailed(False)

每当我尝试登录到 ejabberd web admin (http://localhost:5280/admin/) 时,它都会查询其余服务器,但其余服务器会返回未经授权的 (HTTP 401) 响应。以下是 django 服务器端的响应日志。

"GET /ejabberd/check_password?user=772&server=192.168.1.102&pass=password HTTP/1.1" 401 59

但是,如果我在 浏览器 中使用结果 url http://localhost:8000//ejabberd/check_password?user=772&server=192.168.1.102&pass=password,则会收到 HTTP 响应 200。

django-rest 是否使用任何类型的内置保护来保护跨服务器查询?如果是这样,如何允许查询 ejabberd 服务器。

以下是setting.py

的代码片段
    ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.staticfiles',
    # Rest Framework app
    'rest_framework',
    'rest_framework.authtoken',
    # Internal Apps
    'itiData',
    'ejabberd',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',

    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.DjangoModelPermissions'
    )
}

为了回答我自己的问题,我猜 ejabberd_auth_http 发送基本授权 header 和 url。在 django 功能视图中使用 @authentication_classes([]) 可以解决这个问题。