mozilla / django-browserid

Django application for adding BrowserID support.
Mozilla Public License 2.0
179 stars 80 forks source link

Redirected to logout immediately after login #143

Closed constfun closed 11 years ago

constfun commented 11 years ago

This is a fresh Django 1.5 project, following the docs.

Here are the relevant bits of settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django_browserid',
)

AUTHENTICATION_BACKENDS = (
   'django.contrib.auth.backends.ModelBackend',
   'django_browserid.auth.BrowserIDBackend',
)

TEMPLATE_CONTEXT_PROCESSORS = (
   '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',
   'django_browserid.context_processors.browserid',
)

SITE_URL = 'http://127.0.0.1:8000'
LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL_FAILURE = '/'
LOGOUT_REDIRECT_URL = '/'

# As per Troubleshooting guide, no effect.
SESSION_COOKIE_SECURE = False
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'unique-snowflake'
    }
}

The template.

{% load browserid %}

<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
{% browserid_info %}

<div class="content">
        {% if user.is_authenticated %}
                {% browserid_logout text="Logout" %}
        {% else %}
                {% browserid_login text="Login" %}
        {% endif %}
        {% block content %}{% endblock content %}
</div>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
{% browserid_js %}

</body>
</html>

urls.py

urlpatterns = patterns('',
    url(r'^$', 'mysite.views.home', name='home'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^browserid/', include('django_browserid.urls')),
)

select * from auth_user; shows that the user is being created.

Am I missing something?

Whatever the reason, failing silently makes this a very frustrating thing to debug.

constfun commented 11 years ago

Alright, same code. Works in Safari, DOESN'T work in Chrome.

callahad commented 11 years ago

Oooh, do you have third party cookies disabled in Chrome?

constfun commented 11 years ago

Yes I do... So how would I handle this gracefully for users that have this setting? Is there no way around requiring that this setting be enabled? I can still use OpenID for instance. I've had the setting enabled for a long time and have not experienced issues anywhere.

constfun commented 11 years ago

Enabling third party cookies solves the problem, btw.

callahad commented 11 years ago

We're tracking this in mozilla/browserid#2999 and should have a solution soon-ish.

peterbe commented 11 years ago

https://github.com/mozilla/browserid/issues/2999 is now landed. Can we close this issue?

Osmose commented 11 years ago

@pacemkr Are you still seeing this issue now that mozilla/browserid#2999 is landed?

constfun commented 11 years ago

@Osmose I can't reproduce the issue anymore. I haven't updated django-browserid (or anything else) so it looks like the issue has been fixed. I have third party cookies blocked and everything is working fine in dev and on live. Thank you!