0

I can create my account with Facebook, and when I do I get an auth token back from DRF. But if I click the button again, as if I were logging in, I get a 401 error and the browser pops up a username/password box. It's great that I can create accounts using Facebook, but it would be nice to be able to use Facebook to log in to those accounts! Here's my Python code:

@strategy()
@api_view(['POST'])
def register_by_access_token(request, backend):
    token = request.DATA.get('access_token')
    try:
        user = request.strategy.backend.do_auth(token)
        login(request, user)
        token, created = Token.objects.get_or_create(user=user)
        return Response({"token":token.key, "username":user.username}, status=status.HTTP_201_CREATED)
    except Exception as e:
        return Response({"error":str(e)}, status=status.HTTP_400_BAD_REQUEST)

I never output a 401 response, and don't require a login, so I'm not sure what's up with the 401 error. Any ideas?

jmickela
  • 663
  • 1
  • 8
  • 17

1 Answers1

0

I "solved" this problem by disabling basic and session based authentication for Django REST Framework. That doesn't really explain why I was getting 401 errors before and am not now, but the problem is no longer happening.

jmickela
  • 663
  • 1
  • 8
  • 17