R
R
Robin Alikhanov2020-02-06 18:18:45
Layout
Robin Alikhanov, 2020-02-06 18:18:45

How to connect the authorization module through the social network VKontakte allauth in django?

For half a day I can not connect the authorization module on the local host.
algorithm of actions
1. Installed the module
2. Created migrations
3. installed in INSTALLED_APPS

'allauth',                                  # обычная авторизация
    'allauth.account',
    'allauth.socialaccount',                    # авторизация через социальные сети
    'allauth.socialaccount.providers.vk',


4. registered in setting
# Настройка шаблонов
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], # указываем в какой дирректории лежат наши шаблоны
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

5. Registered in setting
# необходимые настройки для модуля авторизации пользователей
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)


6. Registered in setting
# вместо dummy ставим протокол smtp и тому подобный
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'

# Allauth список настроек для модуля авторизации
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_UNIQUE = True
# ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = True                             # обязательно ли подтверждение через электронную почту
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3                               # время до подтверждения регистрации
ACCOUNT_EMAIL_VERIFICATION = "optional"
ACCOUNT_USERNAME_BLACKLIST = ["admin", "administrator", "moderator"]     # имена которые нельзя использовать при регистрации
ACCOUNT_USERNAME_MIN_LENGTH = 4                                          # минимальное число символов при регистрации
ACCOUNT_USERNAME_REQUIRED = False
LOGIN_REDIRECT_URL = "/"                                                 # куда направить пользователя после авторизации
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = '/'
# ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True


7. I don’t know what to write here
# Provider specific settings настройки для входа через социальные сети
# SOCIALACCOUNT_PROVIDERS = {
# #     'vk': {
# #         # For each OAuth based provider, either add a ``SocialApp``
# #         # (``socialaccount`` app) containing the required client
# #         # credentials, or list them here:
# #         'APP': {

# #         }
# #     }
# # }


8. Registered the application in VK
received:
Application ID ?????????
Protected key ?????????
Service access key ???????????
Site address: specified 127.0.0.1:8000 Base domain: 127.0.0.1 and specified
local host
Trusted redirect URI: localhost : 8000/accounts/vk/login/callback VK Client Id: Specified the Application id that VK issued Secret Key: Specified the Secure Key that the client issued. Sites: in the second column on the right added 127.0.0.1:8000 10. in the Template the button appears but when pressed it displays


{% extends "account/base.html" %}

{% load i18n %}
{% load account socialaccount %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

{% block content %}


{% load socialaccount %}
{% get_providers as socialaccount_providers %}

  <a class="btn btn-social-icon btn-sm btn-vk" href="http://localhost/accounts/vk/login/callback/">
    <span class="fa fa-vk">gggggggggggggggg</span>
  </a>


<h1>{% trans "Sign In" %}</h1>

{% get_providers as socialaccount_providers %}

{% if socialaccount_providers %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>

<div class="socialaccount_ballot">

  <ul class="socialaccount_providers">
    {% include "socialaccount/snippets/provider_list.html" with process="login" %}
  </ul>

  <div class="login-or">{% trans 'or' %}</div>

</div>

{% include "socialaccount/snippets/login_extra.html" %}

{% else %}
<p>{% blocktrans %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}

<form class="login" method="POST" action="{% url 'account_login' %}">
  {% csrf_token %}
  {{ form.as_p }}
  {% if redirect_field_value %}
  <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
  {% endif %}
  <a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
  <button class="primaryAction" type="submit">{% trans "Sign In" %}</button>
</form>

{% endblock %}


Displays a message when clicked
================================
DoesNotExist at /accounts/vk/login/
SocialApp matching query does not exist.
and a lot of errors

link when clicking 127.0.0.1:8000/accounts/vk/login/?process=login

I suspect the dictionary in senng SOCIALACCOUNT_PROVIDERS I don't know how to fill it.
Help me please )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Loginov, 2019-05-23
@pet1987

In your table header, all elements are centered, and in the body of the table they are pressed to the left edge, either do text-align: leftit for th or text-align: centerfor td

D
Dimonchik, 2020-02-08
@dimonchik2013

alas, bro, batteries are not always compatible
only decomposition, iteration and so on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question