A
A
albertalexandrov2018-04-05 07:40:04
Django
albertalexandrov, 2018-04-05 07:40:04

Django-allauth response 302?

Hello!
There is a problem with authorization using social networks. The error lies in the fact that when you click on the registration/authorization link http://MYSITE.ru/accounts/vk/login/?method=oauth2, the browser returns an error ERR_TOO_MANY_REDIRECTS. Error code 302.
Checking on https://bertal.ru gives the following results:

HTTP/1.1 302 Found
Server: nginx
Date: Thu, 05 Apr 2018 04:37:10 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Keep-Alive: timeout=5
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Set-Cookie: sessionid=s6ei8nyhxpx0xvl430zjtrsyimwv1l4i; expires=Thu, 19-Apr-2018 04:37:10 GMT; HttpOnly; Max-Age=1209600; Path=/
Location: https://oauth.vk.com/authorize?redirect_uri=http%3A%2F%2Fyakhshisarova.ru%2Faccounts%2Fvk%2Flogin%2Fcallback%2F&state=fUNKUiqBxJSy&response_type=code&scope=&client_id=280626

The hoster received the following response from the support service:

Hello.
ERR_TOO_MANY_REDIRECTS or circular redirect is usually due to .htaccess settings and link handler in the CMS itself, which sends the client in a loop.
That is, after clicking on "allow", a loop occurs, for example, some header is transmitted or a rule is triggered in .htaccess.
You need to use the "Allow" button link as an example to track where the client is redirected to and what processes this request/following the link.
Apparently the client is redirected again to this form, where he is already authorized. In this situation, a web application developer can help you.

This error is repeated on different devices and browsers.
Application settings in VKontakte (the problem is not only with VKontakte, but also with Instagram):
5ac5a68ea86c7128735822.jpeg
Application settings on the website:
5ac5a6d51b6b8802392618.jpeg
.htaccess settings:
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/realestate.fcgi)
RewriteRule ^(.*)$ cgi-bin/realestate.fcgi/$1 [L]

settings.py settings:
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = SECRET_KEY

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['yakhshisarova.ru', '127.0.0.1']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    'widget_tweaks',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.vk',
    'allauth.socialaccount.providers.instagram'
]

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_EMAIL_REQUIRED = False

SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'realestate.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'realestate.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'HOST': HOST,
        'ENGINE': 'django.db.backends.mysql',
        'NAME': NAME,
        'USER': USER,
        'PASSWORD': PASSWORD,
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
   os.path.join(BASE_DIR, 'static'),
]

LOGIN_REDIRECT_URL = 'index'
LOGOUT_REDIRECT_URL = 'index'
STATIC_ROOT = '/home/httpd/vhosts/yakhshisarova.ru/httpdocs/static'

What could be the problem? How do redirects happen inside the allauth application?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question