omab / django-social-auth

Django social authentication made simple
https://groups.google.com/group/django-social-auth
BSD 3-Clause "New" or "Revised" License
2.65k stars 756 forks source link

Custom template for AuthFailed and AuthCancelled #761

Closed dbrgn closed 11 years ago

dbrgn commented 11 years ago

Can I add custom error templates for the two errors above?

omab commented 11 years ago

You can extend this middleware to force you needed behavior, for example try this:

from social_auth.middleware import SocialAuthExceptionMiddleware
from social_auth.exceptions import AuthFailed, AuthCancelled

class DSAMiddleware(SocialAuthExceptionMiddleware):
    def get_redirect_uri(self, request, exception):
        if isinstance(exception, AuthFailed):
            return '/auth/failed'
        elif isinstance(exception, AuthCancelled):
            return '/auth/cancelled'
        else:
            return super(DSAMiddleware, self).get_redirect_uri(request, exception)

Then define the views for /auth/failed and /auth/cancelled