I'm adding google login to my django app for use in my office only. Logins work fine, but I'm trying to add better error pages. I've written a login error page at /login/error that gives a bit of information about what went wrong, but I can't seem to get django to display that page when its needed.
Logins will fail when the gmail account is not on our companies account (*@myoffice.com) or when the user denies permission. I would like it to redirect to /login/error but the redirect never works.
I have tried adding
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login/error/'
SOCIAL_AUTH_BACKEND_ERROR_URL = '/login/error/'
to my settings.py file. Neither catches the error that I am looking to handle with this page. I can confirm that /login/error works correctly and the issue is just with getting the correct redirect.
Any help would be greatly appreciated.
Update: Heres some more code since this wasn't as quick a fix as I had hoped
From settings.py (key and secret is omitted, whitelisted url is changed)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'thelibrary',
'home',
'social.apps.django_app.default',
)
AUTHENTICATION_BACKENDS = (
'social.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['example.com']
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login/error/'
SOCIAL_AUTH_BACKEND_ERROR_URL = '/login/error/'
From my template that asks a user to login
{% if user and not user.is_anonymous %}
Not yet implemented
{% else %}
Welcome guest!
<br />
Please <a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login with Google</a>
{% endif %}
Heres the error output I get in the console when the request fails
[21/Oct/2014 13:44:42] "GET /login/google-oauth2/ HTTP/1.1" 302 0
[21/Oct/2014 13:44:51] "GET /complete/google-oauth2/?state=3YjuxWntctsrg6emGEPfMjzeeP4NSazX&code=4/lobir0Y2ZZnEPnJRE99gjqhjZh2RbwJC2wfCrs5Zy9A.Envfd1PM7OcaXmXvfARQvtiwnetlkgI HTTP/1.1" 500 157344