Search code examples
pythondjangofacebookfacebook-appspython-social-auth

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. I could "logout" on my Web APP. For example, even if I open a page(view) which has "@login_required" decorator, I cannot open the page. But, I couldn't "logout" facebook itself. 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.

I found a method with 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?

Thank you.

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('/')

Solution

  • I think you can't logout the user using python. See also this post

    But you can easily logout the user using the Javascript SDK:

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