【问题标题】:Logout with python-social-auth使用 python-social-auth 注销
【发布时间】:2017-02-28 17:04:29
【问题描述】:

我使用python-social-auth 进行第三方登录和注销。最初使用 Facebook、Twitter 和 Google Plus 登录是成功的(它会询问我的用户名/电子邮件和密码)。我的问题是当我注销然后通过其中任何一个重新登录时,我将自动登录,甚至无需再次询问我的用户名/电子邮件和密码。我没有登出吗?

这是我的disconnect pipeline

SOCIAL_AUTH_DISCONNECT_PIPELINE = (
    'social.pipeline.disconnect.allowed_to_disconnect',
    'social.pipeline.disconnect.get_entries',
    'social.pipeline.disconnect.revoke_tokens',
    'social.pipeline.disconnect.disconnect',
)

这是我的注销视图:

from django.contrib.auth import logout as auth_logout

def logout(request):
    auth_logout(request)
    return render_to_response('logged-out.html', {}, RequestContext(request))

【问题讨论】:

  • @NuranAfrasiyabov 我已经看到了这个问题并尝试了那里的所有解决方案,但它对我没有帮助。即使我退出,Facebook、Twitter 和 Google Plus 仍处于登录状态。

标签: python django authentication python-social-auth django-socialauth


【解决方案1】:

所以我在我的网站上对此进行了测试。这是解释注销和断开连接行为的链接: http://python-social-auth.readthedocs.io/en/latest/logging_out.html 如您所见,要断开与社交应用程序的连接,您需要使用断开连接(断开连接是您的用户可以要求您的项目“忘记我的帐户”的方式。)。这样,您将删除数据库中 social_auth_usersocialauth 表中的用户关联。为此,您需要执行以下操作:

**settings.py:**
SOCIAL_AUTH_DISCONNECT_PIPELINE = (
# Verifies that the social association can be disconnected from the current
# user (ensure that the user login mechanism is not compromised by this
# disconnection).
#'social.pipeline.disconnect.allowed_to_disconnect',

# Collects the social associations to disconnect.
'social.pipeline.disconnect.get_entries',

# Revoke any access_token when possible.
'social.pipeline.disconnect.revoke_tokens',

# Removes the social associations.
'social.pipeline.disconnect.disconnect',
)

在模板中:

<form id="myform" method="post" action="{% url 'social:disconnect' 'google-oauth2' %}5/?next={{request.path }}">
    {% csrf_token %}
    <input type="hidden" name="name" value="value" /> 
    <a onclick="document.getElementById('myform').submit();">discon</a>
</form>

在第一行中,google-oatuh2 后面的数字 5 表示 DB 表中的用户 ID。因此,下图中的第一个用户将从我的应用程序中删除/断开连接。 要检查断开功能是否有效,请查看您的 social_auth_usersocialauth 表是否已删除用户关联。 但问题是,每当您通过 google、facebook 连接到您自己的应用程序时,这意味着您也在登录 google 或 facebook 网站。(在第一次登录时,它会打开 facebook 或 google 的登录页面)。即使在您与自己的应用程序断开连接后,您也需要从 facebook 或 google 网站注销。否则,您的浏览器将使您保持登录状态,当您再次尝试连接到您的网络应用时,您将自动登录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多