Check Django documentation at `Login URL`_ and `Login redirect URL`_
+ In case of authentication error, the message can be stored in session
+ if the following setting is defined::
+
+ SOCIAL_AUTH_ERROR_KEY = 'social_errors'
+
+ This defined the desired session key where last error message should be
+ stored. It's disabled by default.
+
- Configure authentication and association complete URL names to avoid
possible clashes::
+from django.conf import settings
from django.http import HttpResponseRedirect
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
def error(request):
"""Error view"""
- return render_to_response('error.html', {'version': version},
+ error_msg = request.session.pop(settings.SOCIAL_AUTH_ERROR_KEY, None)
+ return render_to_response('error.html', {'version': version,
+ 'error_msg': error_msg},
RequestContext(request))
def logout(request):
SOCIAL_AUTH_COMPLETE_URL_NAME = 'complete'
LOGIN_ERROR_URL = '/login/error/'
#SOCIAL_AUTH_USER_MODEL = 'app.CustomUser'
+SOCIAL_AUTH_ERROR_KEY = 'socialauth_error'
.helptext {font-size: 0.9em; color: #aaa; margin: 0; padding: 0;}
.description {font-size: 1.0em; color: #333;}
a.logout, .associated, .error {color: #c00;}
+ .error {padding-left: 30px;}
#forkme {position: absolute; top: 0; right: 0;}
#valid-badges {position: absolute; right: 10px; bottom: 10px;}
#valid-badges p {display: inline;}
{% block content %}
<div>
- <p class="error">Sorry but some error made you impossible to login.</p>
+ <p>Sorry but some error made you impossible to login.</p>
+ {% if error_msg %}
+ <p>Details:</p>
+ <p class="error">{{ error_msg }}</p>
+ {% endif %}
<p>Please try again <a href="/">Home</a></p>
</div>
{% endblock %}
backend = get_backend(backend, request, request.path)
if not backend:
return HttpResponseServerError('Incorrect authentication service')
- user = backend.auth_complete()
+
+ try:
+ user = backend.auth_complete()
+ except ValueError, e: # some Authentication error ocurred
+ user = None
+ error_key = getattr(settings, 'SOCIAL_AUTH_ERROR_KEY', None)
+ if error_key: # store error in session
+ request.session[error_key] = str(e)
+
if user and getattr(user, 'is_active', True):
login(request, user)
url = request.session.pop(REDIRECT_FIELD_NAME, '') or \