[Fixed]-Django rest_social_auth log in. What to do with facebook token?

0👍

After some study I found a solution. There are 2 considerations here:

  • Django needs permission and authentication classes

My views.py now looks like this:

class AuthDetailView(BaseDetailView):
    authentication_classes = (TokenAuthentication, )
    permission_classes = IsAuthenticated,
    def get(self, request):
        return render(request, 'home.html')

Notice that I don’t have the @login_required anymore.

  • Django likes the authorization header with a ‘Token’ instead a ‘Bearer’ in front of it

When I make a call to my api, auth header should be like Authorization: Token 4571b2dce1f3abec34b28a4c7bd981c248a30698 instead Authorization: Bearer 4571b2d...

After this changes, request.user is automatically bound to the user previously linked to the token above.

1👍

Add Authorization: Bearer 4571b2dce1f3abec34b28a4c7bd981c248a30698 to the headers as shown below:

enter image description here

Leave a comment