From cc8b115c6ab8265e5122e992a8ebe9960c92ada9 Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Mon, 2 Oct 2017 10:59:52 -0400 Subject: [PATCH] Fix SAML auth behind load balancer issue. Relates to #7586 of ansible-tower as a follow-up of fix #420 of tower. The original fix works for Django version 1.9 and above, this PR expanded the solution to Django verison 1.8 and below. Signed-off-by: Aaron Tan --- awx/sso/strategies/django_strategy.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/awx/sso/strategies/django_strategy.py b/awx/sso/strategies/django_strategy.py index 74fcb94117..0c8c1b492d 100644 --- a/awx/sso/strategies/django_strategy.py +++ b/awx/sso/strategies/django_strategy.py @@ -1,6 +1,10 @@ # Copyright (c) 2017 Ansible, Inc. # All Rights Reserved. +# Django +from django.conf import settings + +# Python social auth from social.strategies.django_strategy import DjangoStrategy @@ -9,8 +13,9 @@ class AWXDjangoStrategy(DjangoStrategy): fixes and updates from social-app-django TODO: Revert back to using the default DjangoStrategy after - we upgrade to social-core / social-app-django. We will also - want to ensure we update the SOCIAL_AUTH_STRATEGY setting. + we upgrade to social-core / social-app-django and upgrade Django + to 1.9 and above. We will also want to ensure we update the + SOCIAL_AUTH_STRATEGY setting. """ def request_port(self): @@ -24,4 +29,7 @@ class AWXDjangoStrategy(DjangoStrategy): try: return host_parts[1] except IndexError: - return self.request.META['SERVER_PORT'] + if settings.USE_X_FORWARDED_PORT and 'HTTP_X_FORWARDED_PORT' in self.request.META: + return self.request.META['HTTP_X_FORWARDED_PORT'] + else: + return self.request.META['SERVER_PORT']