"""Middleware classes for third_party_auth."""fromsocial.apps.django_app.middlewareimportSocialAuthExceptionMiddlewarefrom.importpipelineclassExceptionMiddleware(SocialAuthExceptionMiddleware):"""Custom middleware that handles conditional redirection."""defget_redirect_uri(self,request,exception):
# Safe because it's already been validated by# pipeline.parse_query_params. If that pipeline step ever moves later# in the pipeline stack, we'd need to validate this value because it# would be an injection point for attacker data.auth_entry=request.session.get(pipeline.AUTH_ENTRY_KEY)
# Check if we have an auth entry key we can use insteadifauth_entryandauth_entryinpipeline.AUTH_DISPATCH_URLS:redirect_uri=pipeline.AUTH_DISPATCH_URLS[auth_entry]returnredirect_uri