Authentication credentials were not provided

336 views
Skip to first unread message

Afolabi Oluwapelumi

unread,
Aug 24, 2023, 2:08:41 AM8/24/23
to Django REST framework
I'm writing an api view for sign up for new users but postman is saying : 
{
    "detail": "Authentication credentials were not provided."
}


this is my view: class SignUpAPIView(CreateAPIView):
    serializer_class = SignUpSerializer
   
    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
       
        if serializer.is_valid():
            user = serializer.save()
            return Response({'message': 'User registered successfully'}, status=status.HTTP_201_CREATED)
       
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 


          And serializer: 
class SignUpSerializer(serializers.ModelSerializer):
    email = serializers.EmailField(
        required=True,
        validators=[UniqueValidator(queryset=User.objects.all())]
    )
    password = serializers.CharField(write_only=True, required=True, style={'input_type': 'password'})
    confirm_password = serializers.CharField(write_only=True, required=True, style={'input_type': 'password'})

    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'email', 'password', 'confirm_password']

    def validate(self, data):
        if data['password'] != data['confirm_password']:
            raise serializers.ValidationError("Passwords do not match.")
        return data

    def create(self, validated_data):
        validated_data.pop('confirm_password', None)
        return User.objects.create_user(**validated_data)                                                                



my settings.py: REST_FRAMEWORK = {

    "DEFAULT_AUTHENTICATION_CLASSES": [
        "rest_framework_simplejwt.authentication.JWTAuthentication",
        'rest_framework.authentication.BasicAuthentication',
        "rest_framework.authentication.SessionAuthentication",
    ],

    "DEFAULT_PERMISSION_CLASSES": [
        "rest_framework.permissions.IsAuthenticated"
    ],

Francisco Pandol

unread,
Aug 24, 2023, 8:00:55 AM8/24/23
to django-res...@googlegroups.com
ok, and? What is the problem ? Postman is saying exactly what is the problem. If you want to enable sign up without credentials you should override the permission classes for that endpoint with an empty list or with AllowAny

class SignUpAPIView(CreateAPIView):
    serializer_class = SignUpSerializer
    permission_classes = [AllowAny, ]

Next time please explain your question. And format the text to be easier to read. 
Also read the documentation and use google


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/2658d6dc-6f6f-4858-aa9a-e900e90d1f73n%40googlegroups.com.


--
Francisco Pandol

Afolabi Oluwapelumi

unread,
Aug 24, 2023, 9:02:25 AM8/24/23
to Django REST framework
Thank you very much, I actually thought I added that already. Thank you for the correction 
Reply all
Reply to author
Forward
0 new messages