2

i have added my custom pipeline

SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',

'users.pipeline.return_token', <---- my custom pipeline//
)

pipeline.py

from django.http import JsonResponse, HttpResponse

def return_token(backend, user, response, *args, **kwargs):

if response is not None:
    data = {"token": response['access_token'], "backend": "google-oauth2"}
    return JsonResponse(data)

else:
    return

when the user signup/login the user is registered to database and the access token is returned with no error

when i convert in http://localhost:8000/auth/convert-token

it returns error

AttributeError at /auth/convert-token
'JsonResponse' object has no attribute 'is_active'

when i disable my pipeline there is no error

how can i return access_token without getting error

msd
  • 75
  • 1
  • 8
  • The pipeline expects you to return a `user` object, but you are returning a `JsonResponse`, hence the error. You need to return a user object - you can't return a HTTP response from the pipeline. What are you trying to do with the access token? – solarissmoke Apr 05 '18 at 11:31
  • i will convert the token later to oauth authentication token in http://localhost:8000/auth/convert-token, which is used to access my API. – msd Apr 05 '18 at 11:51
  • is there anyway i can store and access the token later without json or http response since i cant access the logged in user's token – msd Apr 05 '18 at 11:57
  • You can store it if you want to (note that comes with security considerations). You would have to do that in your database or something (i.e., save to a model) which you can do from your pipeline function. I am still not clear why you're trying to return a JSON response though... – solarissmoke Apr 05 '18 at 13:15
  • this is the only way i found, to get user access_token logged in using social network, is there any other way i can get the logged in social user access_token in view? – msd Apr 05 '18 at 13:18

0 Answers0