question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

the user who logined by python-social-auth can't access the page that is only logined user.(Django)

See original GitHub issue

Any user who registers on my homepage directly can access the homepage (which requires the user to be logged in). But a user who registers with python-social-auth can log in, but can’t @@access the homepage.

This is my settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'photo',
    'authentication',
    'social_django',
    'social.apps.django_app.default',
    'pipeline',
    'debug_toolbar',
]

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',

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

            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    'social.backends.kakao.KakaoOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)


PIPELINE = {
    'PIPELINE_ENABLED': True,
    'JAVASCRIPT': {
        'stats': {
            'source_filenames': (
              'js/jquery.js',
              'js/d3.js',
              'js/collections/*.js',
              'js/application.js',
            ),
            'output_filename': 'js/stats.js',
        }
    }
}

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.user.get_username',
    'social.pipeline.user.user_details',
    'authentication.social.require_info',
    'social.pipeline.mail.mail_validation',
    'social.pipeline.social_auth.associate_by_email',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',

)

SOCIAL_AUTH_DISCONNECT_PIPELINE = (
    'social.pipeline.disconnect.allowed_to_disconnect',
    'social.pipeline.disconnect.get_entries',
    'social.pipeline.disconnect.revoke_tokens',
    'social.pipeline.disconnect.disconnect',
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
SOCIAL_AUTH_KAKAO_KEY ='d3b5de655df7bbfc85916336a9c4a479'

SOCIAL_AUTH_KAKAO_SECRET = ''

SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'email']
SOCIAL_AUTH_SLUGIFY_USERNAMES = True

SOCIAL_AUTH_LOGIN_REDIRECT_URL ='/home'
SOCIAL_AUTH_LOGIN_URL ='/accounts.kakao.com/login'
SOCIAL_AUTH_URL_NAMESPACE = 'social'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

this is urls.py

#login
url(r'^accounts/login/$', auth_views.login, {'template_name':'registration/login.html', 'authentication_form': LoginForm}, name='login'),
url(r'^accounts/logout/$', auth_views.logout, {'next_page':'/accounts/login'}, name='logout'),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^accounts/register/$', UserCreateView.as_view(), name='register'),
url(r'^accounts/getinfo/$', authentication_views.acquire_info, name='acquire_info'),
]

this is templates

<div class="container">
    <div class="center-form panel">
        <div class="panel-body">
            <h4 class="text-center"><i class="ion-log-in"></i>Log in</h4>

            <form method="post" action="{% url 'login' %}">
            {% csrf_token %}
                <div class="form-group has-feedback">
                <p>{{user.username}} 반갑습니다.</p>

                {{ form.username }}
                <span class="ion-person form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                {{ form.password }}
                    <span class="ion-key form-control-feedback"></span>
                </div> 

                <button type="submit" class="btn btn-block btn-success" value="login">Log in</button>

                <br />

                <p class="text-center text-muted">
                    <small>Don't have an account yet? <a href="{% url 'register' %}">Sign up</a></small>
                </p>

                <div class="signup-or-separator">
                    <h6 class="text">or</h6>
                    <hr>
                </div>
                <input type="hidden" name="next" value="{{next}}" />
            </form>
            <a href="{% url 'social:begin' backend='kakao' %}?next={{request.path}}" class="btn btn-block btn-kakao">
                카카오계정으로 로그인
            </a>
        </div>
 </div>
</div>   

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Nuqlearcommented, Feb 23, 2017

I have the same problem – I cant access views with login_required decorator (from django.contrib.auth.decorators) after logging through SteamOpenId. However if I login in django-admin then I can see there that user is successfully created/associated. What could I miss?

EDIT: Problem was gone after social.backends.steam.SteamOpenId was replaced with social_core.backends.steam.SteamOpenId.

0reactions
triflecommented, May 5, 2017

Thanks @Nuqlear for the hint - this hit me as well. Maybe the configuration switch from to social_core.backends could get fixed in the docs here?

http://python-social-auth.readthedocs.io/en/latest/configuration/django.html#template-context-processors

That would be great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

python-social-auth: Unable to keep logged in newly registered ...
In summary, and to avoid overflowing with data here, everything works as expected, but as soon as I save the password via user.set_password( ......
Read more >
Customizing authentication in Django
When somebody calls django.contrib.auth.authenticate() – as described in How to log a user in – Django tries authenticating across all of its authentication ......
Read more >
Configuration — Python Social Auth documentation
Like SOCIAL_AUTH_NEW_USER_REDIRECT_URL but for new associated accounts (user is already logged in). Used in place of SOCIAL_AUTH_LOGIN_REDIRECT_URL.
Read more >
Integrate OAuth 2 Into Your Django/DRF Back-end | Toptal
Once you've received the access token from the server, your server then redirects the user's browser once more to the landing page for...
Read more >
Adding Social Authentication to Django - TestDriven.io
A user attempts to log in to your app using their account from a ... Django Allauth and Python Social Auth are the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found