1

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('/')
yamachan
  • 1,029
  • 2
  • 12
  • 28

2 Answers2

1

I haven't used python-social-auth, but technically you cannot.

When user logs in via Outh2.0, user is directed to social site's URL, where user logs in to that social site. After that one of your URLs or methods is called by the social site to tell you that user is authenticated. Your servers or code is never involved in this login process, so you cannot interfere with it and logout user.

Muhammad Tahir
  • 5,006
  • 1
  • 19
  • 36
  • Thank you for your advice, Muhammad Tahir. I got it. I will implement SDK instead. Thank you very much. – yamachan Feb 25 '16 at 15:16
1

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> 
Community
  • 1
  • 1
ilse2005
  • 11,189
  • 5
  • 51
  • 75