0

I have a use-case where I have to login a user from different application in my django application.

The user will click a button in the primary application where the user data like username, firstname, lastname and userid is sent to me as jwt token.

In my application I am decrypting the jwttoken and fetching the user data json and then using

django.contrib.auth import login 

method to login the user and then sending the response

user = User.objects.get(user_name=user_name)
login(request, user)
response = HttpResponse(json.dumps({'message': "you are successfully logined in"}), content_type='application/json')
response.status_code = 200
return response  

where in the primary application then the user is redirected to dashboard of my application whose view is

@login_required(login_url='/testserver/user/login/')
def dashboard(request):
     user = User.objects.get(user_name=request.user)
     return render(request, 'home.html', {'user':user})

The problem is that the user is redirected to /testserver/user/login/ URL and if I remove it @login_required(login_url='/testserver/user/login/'), then i see that request.user is AnonymousUser.

How can I fix this to make it end to end working?

jbaptperez
  • 656
  • 6
  • 20

0 Answers0