2015-10-20 134 views
2

我试图使用ejabberd_auth_http模块进行ejabberd服务器中的用户身份验证。因此,对于身份验证,ejabberd服务器(http://localhost:5222)将对django rest服务器进行查询,并检查用户是否存在提供的凭证。 django服务器中的GET请求处理程序如下。Ejabberd身份验证http查询Django服务器未经身份验证

@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管理(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' 
    ) 
} 

回答

0

的代码片段要回答我的问题,我想ejabberd_auth_http将基本授权标头的URL。在django功能视图中使用@authentication_classes([])可以解决问题。