2015-10-20 147 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([])可以解決問題。