omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Redirect to accounts/login after correct login. Custom pipeline #1079

Closed zelds closed 7 years ago

zelds commented 7 years ago

After correct login redirect me to accounts/login, does not create "User social auths" and some times in "User social auths" id is id of superuser. But i logout before login from steam. Marker from custom pipeline create correct. All trouble is redirect to /accounts/login and does not creating user in default user model and in social user model. When i remove all SOCIAL_AUTH_PIPELINE from settings all works fine.

settings.py

INSTALLED_APPS = (
...
    # Installed
    'social_django',
...
)
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/logged-in/'
AUTHENTICATION_BACKENDS = (
    'social.backends.steam.SteamOpenId',
    'django.contrib.auth.backends.ModelBackend',
)
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',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'markers.pipeline.add_steam_data_marker',
)
SOCIAL_AUTH_STEAM_API_KEY = "35F77A9F5AE***********CEB2C67F4951683E"
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_django.context_processors.backends',
                'social_django.context_processors.login_redirect',

            ],
        },
    },
]

cutom pipeline

def add_steam_data_marker(strategy, details, backend, uid, user=None, *args, **kwargs):
    if backend.name == 'steam':
        data = json.loads(str(details).replace("'", "\""))
        time_created = datetime.fromtimestamp(data['player']['timecreated'])

        Marker.objects.create(
            games=steam_user.games,
            nickname=data['player']['personaname'],
            time=time_created,
            avatar=data['player']['avatar'],
            real_name=data['player']['realname'],
            country_code=data['player']['loccountrycode'],
            steam_url=data['player']['profileurl'],
            steam_id=uid,
        )

pip freeze defusedxml==0.4.1 Django==1.10.4 django-geoposition==0.3.0 future==0.16.0 httplib2==0.9.2 oauth2==1.9.0.post1 oauthlib==2.0.1 Pillow==3.4.2 psycopg2==2.6.2 pycryptodomex==3.4.3 pyjwkest==1.3.2 PyJWT==1.4.2 python-openid==2.2.5 python-social-auth==0.3.3 python3-openid==3.0.10 requests==2.12.4 requests-oauthlib==0.7.0 six==1.10.0 social-auth-app-django==0.1.0 social-auth-core==0.1.0 steamapi==0.1

zelds commented 7 years ago

Trouble was with wrong pipeline documentation. we need 'social.pipeline.user.create_user', before 'social.pipeline.social_auth.associate_user',

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    # After this write ur custom pipelines
)