简体   繁体   English

使用django和django_openid_auth注销

[英]logout with django and django_openid_auth

I successfully got django_openid_auth working in my django project, and can now login with my Google account. 我已成功在django项目中使用django_openid_auth,并且现在可以使用我的Google帐户登录。 What I can't figure out is how to logout. 我不知道如何注销。 The standard django.contrib.auth.views.logout view will logout the user, but subsequently visiting a page that requires authentication will authenticate the user again without a prompt. 标准django.contrib.auth.views.logout视图将注销用户,但是随后访问需要身份验证的页面将再次对用户进行身份验证,而不会出现提示。 How can I completely logout the user? 如何完全注销用户?

One of the purposes of OpenId is to simplify logging in process. OpenId的目的之一是简化登录过程。 Behaviour that you are experiencing is absolutelly correct . 您所经历的行为是绝对正确的 First time you were logging in to your application with your Google account, you allowed OpenId provider (Google) to send data to your application. 首次使用Google帐户登录应用程序时,您允许OpenId提供程序(Google)将数据发送到您的应用程序。 As the data is still in database you don't have to be prompted again for allowing access. 由于数据仍在数据库中,因此无需再次提示允许访问。

Nevertheless if you want to be prompted again you should clear the data from database manually. 但是,如果要再次提示,则应手动从数据库中清除数据。 You can do this by creating custom logout view or by using Signal infrastructure and adding the following: 您可以通过创建自定义注销视图或使用Signal基础结构并添加以下内容来执行此操作:

from django.contrib.auth.signals import user_logged_out
@receiver(user_logged_out)    
def clear_openid_data(sender, user,**kwargs):
    # wipe out data according to models in django_openid_auth..

to signals.py 到signal.py

It's worth mentioning that user_logged_out is available since Django 1.3 值得一提的是,自Django 1.3起, user_logged_out可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM