pythondjangofacebookpython-social-auth

ImproperlyConfigured: The SECRET_KEY setting must not be empty error after editing django auth pipeline


I added python-social-auth for Facebook login, and after adding the file with custom piplene function my project had stopped working. All operations fail with the known problem:

ImproperlyConfigured: The SECRET_KEY setting must not be empty.

As I see from many others post, the reason is in a circular dependencies, but I can't imagine where is it.

Here is the listing of settings.py:

import os

from config import *
from FBAuth.facebook import *
....

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'FBAuth',
'social.apps.django_app.default',    
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
'social_auth.middleware.SocialAuthExceptionMiddleware',
)


AUTHENTICATION_BACKENDS = (
'social.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.core.context_processors.debug',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',                
            'django.contrib.messages.context_processors.messages',
            'social.apps.django_app.context_processors.backends',
            'social.apps.django_app.context_processors.login_redirect',                
        ],
    },
},
]


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',
            'social.apps.django_app.context_processors.backends',
            'social.apps.django_app.context_processors.login_redirect',   
            
        ],
    },
},
 ]

SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy'
SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage'
FIELDS_STORED_IN_SESSION = ['login_type']
LOGIN_ERROR_URL = '/login_error/'

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'FBLogin.facebook.check_if_exists',     
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
)

note: I removed all unrelated default settings

facebook.py:

from django.shortcuts import  redirect
from django.contrib.auth.models import User
from social.exceptions import AuthCanceled    

def check_if_exists(*args, **kwargs):
    #request = kwargs.get('request')
     if kwargs['is_new']:
        if request.session['login_type'] == 'login': #need to add message
            raise AuthCanceled
    else: 
        if request.session['login_type'] == 'signup':  #need to add message
            raise AuthCanceled
    return None

I am trying to figure out where the blocking issue is.


Solution

  • Try to remove this unnecessary line from your setting.py:

    from FBAuth.facebook import *