/ / Django-rest-framework s django OAuth 2.0 poskytujúcou autentifikačnú chybu - python, django, oauth, django-rest-framework, django-oauth

Django-rest-framework s django OAuth 2.0 poskytujúcou autentifikačnú chybu - python, django, oauth, django-rest-framework, django-oauth

Mám integrovaný django-rest-framework s django-oauth-toolkit. A dáva mi to {"detail": "Authentication credentials were not provided."} s autentifikovaným apisom.

Tu je môj setup.py

REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"oauth2_provider.contrib.rest_framework.OAuth2Authentication",
),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAuthenticated",
)
}

views.py

from rest_framework.views import APIView
from rest_framework.response import Response


class SignUpView(APIView):
"""
Signup for the user.
"""
def get(self, request):
return Response({"result": True, "message": "User registered successfully."})

urls.py

from django.urls import path
from myapp.views import SignUpView

urlpatterns = [
path("signup/", SignUpView.as_view()),

]

odpovede:

0 pre odpoveď č. 1

Pri registrácii používateľa nepotrebujete žiadne overovanie. Takže musíte napísať svoj pohľad takhle.

class SignUpView(APIView):
"""
Signup for the user.
"""
authentication_classes = ()
permission_classes = ()

def get(self, request):
return Response({"result": True, "message": "User registered successfully."})

Pri všetkých ostatných žiadostiach musíte v hlavičke odoslať token auth. V tomto prípade nebudete musieť spomenúť triedy autentifikácie a povolení, pretože sa použijú predvolené triedy.