I have integrated google social auth in my django + react.js project. I am using the access token that I am getting from google to call this url 'http://localhost:8000/auth/convert-token'
. This is giving me a json response which contains the access-token and the refresh-token. However I want to add the user name in that json response as well. I tried using request.user.username. But it is not giving me anything. I guess it is because by the time the call is made the for aforementioned URL, the request doesn't have any value for the currently logged in user.
Can you suggest me any way to get the username.
Following is my code.
@api_view(["POST"])
def googleSignIn (request):
print(request.headers.get("token"))
resposnePayload = {}
# token obtained from google
token = request.headers.get("token")
clientId = "<client-id for django app>"
clientSecret = "<client-secret for django app>"
url = 'http://localhost:8000/auth/convert-token'
header = {
"Content-Type": "application/x-www-form-urlencoded"
}
payload = {
"grant_type": 'convert_token',
"client_id" : clientId,
"client_secret" :clientSecret,
"backend":"google-oauth2",
"token":token
}
result = requests.post(url,data=payload,headers = header)
resopnsePayload=result.json()
print("currently logged in user is ",request.user.username)
return Response(resopnsePayload,status=result.status_code)