简体   繁体   English

如何使用python-social-auth在Django APP上注销Facebook本身?

[英]How can I logout facebook itself on Django APP with python-social-auth?

Excuse me, I have a question. 对不起,我有一个问题。 I wrote facebook Auth script with Django and python-social-auth. 我用Django和python-social-auth编写了Facebook Auth脚本。 I could "logout" on my Web APP. 我可以在Web APP上“注销”。 For example, even if I open a page(view) which has "@login_required" decorator, I cannot open the page. 例如,即使我打开具有“ @login_required”修饰符的页面(视图),也无法打开该页面。 But, I couldn't "logout" facebook itself. 但是,我无法“注销” facebook本身。 For instance, when I click "login with facebook", I can login on facebook without visiting facebook page, and when I visit facebook, my wall is appeared. 例如,当我单击“使用Facebook登录”时,无需登录Facebook页面就可以登录Facebook,而当我访问Facebook时,我的墙就会出现。

I found a method with PHP, 我找到了使用PHP的方法,

function logout() {
    $this->session->sess_destroy();
    $this->facebook->destroySession();
    redirect('index/', 'location');
}

But how can I logout facebook through my Web APP with Python3 and Django1.9? 但是,如何使用Python3和Django1.9通过Web APP注销Facebook?

Thank you. 谢谢。

views.py views.py

from django.shortcuts import render
from django.shortcuts import redirect
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
from django.template.context import RequestContext


def login(request):
    context = RequestContext(request, {
        'request': request, 'user': request.user})
    return render(request, 'myapp/login/login.html' context_instance=context)


@login_required(login_url='/')
def home(request):
    return render(request, 'myapp/login/home.html')


def logout(request):
    auth_logout(request)
    return redirect('/')

I haven't used python-social-auth, but technically you cannot. 我没有使用python-social-auth,但从技术上讲您不能使用。

When user logs in via Outh2.0, user is directed to social site's URL, where user logs in to that social site. 当用户通过Outh2.0登录时,用户将被定向到社交网站的URL,即用户在该URL上登录。 After that one of your URLs or methods is called by the social site to tell you that user is authenticated. 之后,社交网站会调用您的URL或方法之一,以告诉您该用户已通过身份验证。 Your servers or code is never involved in this login process, so you cannot interfere with it and logout user. 您的服务器或代码永远不会参与此登录过程,因此您不会干扰它或注销用户。

I think you can't logout the user using python. 我认为您无法使用python注销用户。 See also this post 另请参阅这篇文章

But you can easily logout the user using the Javascript SDK: 但是您可以使用Javascript SDK轻松注销用户:

<a href="/logout" onclick="FB.logout();">Logout</a> 

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

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