Question

I have a Django-social-auth on my test project. I need to make authentication throw "vkontakte" (its a popular social network in russia). Docs. So, in /etc/hosts I have:

#127.0.0.1  localhost
127.0.1.1   pc-my-motherboard
127.0.0.1   domain.com

I add social_auth to the Installed apps, here is some code from settings:

VK_APP_ID = '123456'
VK_API_SECRET = 'secrets :)'
VK_EXTRA_SCOPE = ['notify', 'friends', 'status', 'groups', 'notifications']


# Добавляем в AUTHENTICATION_BACKENDS нужные бекенды
AUTHENTICATION_BACKENDS = (
    'social_auth.backends.contrib.vkontakte.VKontakteOAuth2Backend',
    'django.contrib.auth.backends.ModelBackend',
)

# Добавляем в TEMPLATE_CONTEXT_PROCESSORS процессор "social_auth_by_name_backends"
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'social_auth.context_processors.social_auth_by_name_backends',
    'social_auth.context_processors.social_auth_backends',
    'social_auth.context_processors.social_auth_by_type_backends',
    'social_auth.context_processors.social_auth_login_redirect',
)

# Если имя не удалось получить, то можно его сгенерировать
SOCIAL_AUTH_DEFAULT_USERNAME = lambda: random.choice(['0', '1', '2', '3', '4', '5'])

# Разрешаем создавать пользователей через social_auth
SOCIAL_AUTH_CREATE_USERS = True

# Перечислим pipeline, которые последовательно буду обрабатывать респонс 
SOCIAL_AUTH_PIPELINE = (
    # Получает по backend и uid инстансы social_user и user
    'social_auth.backends.pipeline.social.social_auth_user',
    # Получает по user.email инстанс пользователя и заменяет собой тот, который получили выше.
    # Кстати, email выдает только Facebook и GitHub, а Vkontakte и Twitter не выдают
    #'social_auth.backends.pipeline.associate.associate_by_email',
    # Пытается собрать правильный username, на основе уже имеющихся данных
    'social_auth.backends.pipeline.user.get_username',
    # Создает нового пользователя, если такого еще нет
    'social_auth.backends.pipeline.user.create_user',
    # Пытается связать аккаунты
    'social_auth.backends.pipeline.social.associate_user',
    # Получает и обновляет social_user.extra_data
    'social_auth.backends.pipeline.social.load_extra_data',
    # Обновляет инстанс user дополнительными данными с бекенда
    'social_auth.backends.pipeline.user.update_user_details'
)

SOCIAL_AUTH_UID_LENGTH = 223
SOCIAL_AUTH_NONCE_SERVER_URL_LENGTH = 18
SOCIAL_AUTH_ASSOCIATION_SERVER_URL_LENGTH = 18
SOCIAL_AUTH_ASSOCIATION_HANDLE_LENGTH = 223
SOCIAL_AUTH_UUID_LENGTH = 16

In urls:

urlpatterns = patterns('',
    url(r'$', 'myapp.views.index', name='index'),
    url(r'', include('social_auth.urls')),

)

in index.html:

<p>Hello {{ user }}</p>

<a href="{% url 'socialauth_begin' 'vkontakte-oauth2' %}">Enter VK</a>

Then I start server: sudo python manage.py runserver 127.0.0.1:80. I see the link, I press and it go to the http://domain.com/login/vkontakte-oauth2/. Last time this show authentication form social network, and redirrect to my site, now it doesnt happen. Its very strange, because all the settings a true, please, help me to fix it.

Thanks.

Was it helpful?

Solution 2

Oh, the error is in url(r'^$', in urls. Only hardcore

OTHER TIPS

Could you precise what's happening when you try to access the form ? Do you see a specific error ? When I try access the form for this social network on the django-social-auth demo I get an error. Maybe the part of the app concerning vkontakte is bugged, it seems the domain name used for the redirection is bad. You may check if the url you try to access corresponds to the one normally used to log in on the social network.

Regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top