From f44adb98cbbf16b8384fb8e7794feff6e8ba7798 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Wed, 13 Sep 2017 21:16:10 -0400 Subject: [PATCH 1/2] update social auth strategy to have fixes from social-app-django --- awx/settings/defaults.py | 2 +- awx/sso/strategies/__init__.py | 2 ++ awx/sso/strategies/django_strategy.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 awx/sso/strategies/__init__.py create mode 100644 awx/sso/strategies/django_strategy.py diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index c4af5d8d10..76ce8414c1 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -491,7 +491,7 @@ else: } # Social Auth configuration. -SOCIAL_AUTH_STRATEGY = 'social.strategies.django_strategy.DjangoStrategy' +SOCIAL_AUTH_STRATEGY = 'awx.sso.strategies.django_strategy.AWXDjangoStrategy' SOCIAL_AUTH_STORAGE = 'social.apps.django_app.default.models.DjangoStorage' SOCIAL_AUTH_USER_MODEL = AUTH_USER_MODEL # noqa SOCIAL_AUTH_PIPELINE = ( diff --git a/awx/sso/strategies/__init__.py b/awx/sso/strategies/__init__.py new file mode 100644 index 0000000000..46176c348f --- /dev/null +++ b/awx/sso/strategies/__init__.py @@ -0,0 +1,2 @@ +# Copyright (c) 2017 Ansible, Inc. +# All Rights Reserved. diff --git a/awx/sso/strategies/django_strategy.py b/awx/sso/strategies/django_strategy.py new file mode 100644 index 0000000000..94b25ae14c --- /dev/null +++ b/awx/sso/strategies/django_strategy.py @@ -0,0 +1,26 @@ +# Copyright (c) 2017 Ansible, Inc. +# All Rights Reserved. + +from social.strategies.django_strategy import DjangoStrategy + + +class AWXDjangoStrategy(DjangoStrategy): + """A DjangoStrategy for python-social-auth containing + fixes and updates from social-app-django + """ + + def __init__(self, storage, request=None, tpl=None): + super(AWXDjangoStrategy, self).__init__(storage, tpl) + + def request_port(self): + """Port in use for this request + https://github.com/python-social-auth/social-app-django/blob/master/social_django/strategy.py#L76 + """ + try: # django >= 1.9 + return self.request.get_port() + except AttributeError: # django < 1.9 + host_parts = self.request.get_host().split(':') + try: + return host_parts[1] + except IndexError: + return self.request.META['SERVER_PORT'] From 5cc0552b05a93b21da5863072d4904c7d93f3fb7 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Wed, 13 Sep 2017 21:28:26 -0400 Subject: [PATCH 2/2] remove AWXDjangoStrategy in the future --- awx/sso/strategies/django_strategy.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx/sso/strategies/django_strategy.py b/awx/sso/strategies/django_strategy.py index 94b25ae14c..728e380dc4 100644 --- a/awx/sso/strategies/django_strategy.py +++ b/awx/sso/strategies/django_strategy.py @@ -7,6 +7,10 @@ from social.strategies.django_strategy import DjangoStrategy class AWXDjangoStrategy(DjangoStrategy): """A DjangoStrategy for python-social-auth containing 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. """ def __init__(self, storage, request=None, tpl=None):