Я пишу приложение Ionic 3 с бэкэндом Django.
Мне уже удалось войти в систему таким образом с помощью Facebook (с помощью social_django), но я не могу позволить себе отключиться от него (поэтому я удаляю свое приложение из списка приложений для Facebook).
Здесьнекоторые части моего кода:
setting.py
SOCIAL_AUTH_FACEBOOK_KEY = '**********************'
SOCIAL_AUTH_FACEBOOK_SECRET = '***********************'
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.get_username',
'social_core.pipeline.user.create_user',
'main.views.register_social',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
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_core.pipeline.disconnect.allowed_to_disconnect',
# Collects the social associations to disconnect.
'social_core.pipeline.disconnect.get_entries',
# Revoke any access_token when possible.
'social_core.pipeline.disconnect.revoke_tokens',
# Removes the social associations.
'social_core.pipeline.disconnect.disconnect',
)
urls.py
urlpatterns = [
url(r'^register-by-token/(?P<backend>[^/]+)/$', register_by_access_token, name = 'register_by_access_token'),
url(r'^disconnect-from/(?P<backend>[^/]+)/$', disconnect_from_facebook, name = 'disconnect_from_facebook'),
]
views.py
from social_core.actions import do_disconnect
from social_django.utils import psa
@psa('social:complete')
def register_by_access_token(request, backend):
token = request.GET.get('access_token')
user = request.backend.do_auth(token, ajax = True)
if user:
login(request, user)
return HttpResponse()
else:
return HttpResponseBadRequest()
@csrf_exempt
def disconnect_from_facebook(request, backend):
user = request.user
username = user.username
utente = Utente.objects.get(username = username)
do_disconnect(backend, user = utente)
def register_social(backend, user, response, strategy, *args, **kwargs):
member_exists = Utente.objects.filter(user_ptr = user).exists()
strategy = backend.strategy
if member_exists:
member = Utente.objects.get(user_ptr = user)
else:
member = Utente(user_ptr = user)
member.__dict__.update(user.__dict__)
member.save()
feeds = Feed.objects.all()
member.feed.add(*feeds)
У меня уже есть документация на целый день, чтобы позволить себе это, и я видел несколько других сообщений (таких как: python-social-auth - как я могу отключиться в Django?) но никто не подходит к моему случаю: (
Заранее спасибо.