1

I'm using vue.js for the front end of my application which is made on Django-restframework. I am using django-rest-auth for social authentication via Google.

On the front end, I am using the vue-google-oauth2 library. The two work fine. I send an auth code from the front end and the backend responds with a token key. However, when I use curl on my terminal with the key

curl -X GET http://127.0.0.1:8000/api/example/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'

I get the error:

{"detail":"Authentication credentials were not provided."}

With my terminal showing:

[06/Mar/2019 15:38:54] "GET /newsfeed/ HTTP/1.1" 401 58

What is it that I am supposed to do to ensure that the cookies or whatever it is at the backend to maintain my session isn't lost?

Similarly, when I login on the front end using the oauth2 library, I refresh my page and that too shows that I am no longer logged in.

What exactly am I missing out on?

1 Answer 1

1

looks like 1st authentication class is set to base authentication. make sure you activate tokenbase authentication for that view as 1st authentication class. or you can set authentication class globally in setting.py.

if you are using class base view . do it like this

class AccountDetailsView(RetrieveAPIView):
    authentication_classes = [TokenAuthentication,BasicAuthentication]
    serializer_class = AccountDetails
    permission_classes = [IsAuthenticated, ]
Sign up to request clarification or add additional context in comments.

1 Comment

OMG. I set the token authentication class in settings.py as you suggested and I think it's working fine now! Thank you so much. Now I just need to figure what I need to do with the front end not retaining its session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.