RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Authenticated requests not working #215

Closed itsnikhil closed 4 years ago

itsnikhil commented 4 years ago

I have my view which looks like this

def hello(request):
   return HttpResponse(str(request.user))

curl -H "Authorization: Bearer <my-token-returned-by-posting-to-/auth/token-with-form-data>" -X GET http://localhost:8000/

The above command returns "AnonymousUser"

I am following the readme and was able to generate tokens but i am not able to "Manage Authenticated Requests"

sereneinserenade commented 4 years ago

Hey Nikhil, maybe you're having the problem because you haven't included the <backend-name>

image image
ZunaedSifat commented 4 years ago

Hi @itsnikhil , I am having exactly the same problem. Could you solve it somehow?

itsnikhil commented 4 years ago

Hi @itsnikhil , I am having exactly the same problem. Could you solve it somehow?

Hi @ZunaedSifat, Yes I was able to fix the issue. I don't exactly remember how. I think I made the below mentioned changes. Please try it out once and let me know

from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import permission_classes, api_view

@api_view(['GET'])
@permission_classes((IsAuthenticated, ))
def hello(request):
   text = {'message': str(request.user)}
   return Response(text)