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

孤街醉人 提交于 2019-12-07 01:52:30

问题


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.

<li>
    <a class="btn" href="" 
        onclick="window.open('{% 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 views.py also.


回答1:


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.




回答2:


I had the same issue. My solution was to set the successful redirect login in my settings.py file. SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/close/'

Then map that in my urls file url(r'^close/$', TemplateView.as_view(template_name='close.html')),

Then have my close.html contain a single script tag to close the browser window on load without triggering a confirmation popup.

<script>
    window.open('', '_self', ''); window.close();
</script>


来源:https://stackoverflow.com/questions/23224434/open-new-window-for-social-login-and-then-close-and-return-to-parent-on-success

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!