gh0st gh0st - 1 year ago 615
Javascript Question

Open New Window for Social Login and then Close and Return to Parent On Success with Django

I'm working with Django 1.6.2 and Python-Social-Auth 0.1.23.
I'm also working with Twitter Bootstrap as my templating engine.

I've worked python-social-auth into my template and implemented a LinkedIn log in for my customers and I've coded it so that the login opens in a new window using javascript.

<a class="btn" href=""
onclick="'{% url 'social:begin' 'linkedin' %}', '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
<span class="glyphicon glyphicon-user"></span> Sign In</a></li>

My question is, how can I close this child window and reload the parent window upon successful login?

I realize this question might be pretty specific but someone has had to implement the same idea before. Just a little heads up: if I can, I don't want to edit any of the python-social-auth stuff.

Let me know if there is any other information you could use. I can include my also.

Answer Source

You solved the opening-in-a-popup part already, the closing is the tricky one, for that you need to serve some page with the needed JS code to close the popup and then trigger the reload in the parent window. To make that possible, just define the setting SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/page/that/servers/the/js' and then create the view/template that does that.

Check around how closing and triggering reload in the parent is done, it's quite easy, and serve that JS to the user.