From cd344139141e9ba4f49c278536c4616b1afe4390 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 2 Jan 2020 16:07:33 +0100 Subject: [PATCH] providers/app_gw: separate host field into external_ and internal_ --- passbook/providers/app_gw/forms.py | 11 +++++---- .../migrations/0004_auto_20200102_1505.py | 24 +++++++++++++++++++ passbook/providers/app_gw/models.py | 3 ++- .../app_gw/templates/app_gw/setup_modal.html | 4 ++-- 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 passbook/providers/app_gw/migrations/0004_auto_20200102_1505.py diff --git a/passbook/providers/app_gw/forms.py b/passbook/providers/app_gw/forms.py index cac988948..ecb2bd914 100644 --- a/passbook/providers/app_gw/forms.py +++ b/passbook/providers/app_gw/forms.py @@ -20,8 +20,10 @@ class ApplicationGatewayProviderForm(forms.ModelForm): "code" ) self.instance.client.redirect_uris = [ - f"http://{self.instance.host}/oauth2/callback", - f"https://{self.instance.host}/oauth2/callback", + f"http://{self.instance.external_host}/oauth2/callback", + f"https://{self.instance.external_host}/oauth2/callback", + f"http://{self.instance.internal_host}/oauth2/callback", + f"https://{self.instance.internal_host}/oauth2/callback", ] self.instance.client.scope = ["openid", "email"] self.instance.client.save() @@ -30,8 +32,9 @@ class ApplicationGatewayProviderForm(forms.ModelForm): class Meta: model = ApplicationGatewayProvider - fields = ["name", "host"] + fields = ["name", "internal_host", "external_host"] widgets = { "name": forms.TextInput(), - "host": forms.TextInput(), + "internal_host": forms.TextInput(), + "external_host": forms.TextInput(), } diff --git a/passbook/providers/app_gw/migrations/0004_auto_20200102_1505.py b/passbook/providers/app_gw/migrations/0004_auto_20200102_1505.py new file mode 100644 index 000000000..2eb2d959f --- /dev/null +++ b/passbook/providers/app_gw/migrations/0004_auto_20200102_1505.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-01-02 15:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("passbook_providers_app_gw", "0003_applicationgatewayprovider"), + ] + + operations = [ + migrations.RenameField( + model_name="applicationgatewayprovider", + old_name="host", + new_name="external_host", + ), + migrations.AddField( + model_name="applicationgatewayprovider", + name="internal_host", + field=models.TextField(default=""), + preserve_default=False, + ), + ] diff --git a/passbook/providers/app_gw/models.py b/passbook/providers/app_gw/models.py index 71e0b2044..74522c23a 100644 --- a/passbook/providers/app_gw/models.py +++ b/passbook/providers/app_gw/models.py @@ -14,7 +14,8 @@ class ApplicationGatewayProvider(Provider): """This provider uses oauth2_proxy with the OIDC Provider.""" name = models.TextField() - host = models.TextField() + internal_host = models.TextField() + external_host = models.TextField() client = models.ForeignKey(Client, on_delete=models.CASCADE) diff --git a/passbook/providers/app_gw/templates/app_gw/setup_modal.html b/passbook/providers/app_gw/templates/app_gw/setup_modal.html index 8534ef822..650820b41 100644 --- a/passbook/providers/app_gw/templates/app_gw/setup_modal.html +++ b/passbook/providers/app_gw/templates/app_gw/setup_modal.html @@ -40,10 +40,10 @@ services: environment: OAUTH2_PROXY_CLIENT_ID: {{ provider.client.client_id }} OAUTH2_PROXY_CLIENT_SECRET: {{ provider.client.client_secret }} - OAUTH2_PROXY_REDIRECT_URL: https://{{ provider.host }}/oauth2/callback OAUTH2_PROXY_OIDC_ISSUER_URL: https://{{ request.META.host }}/application/oidc + OAUTH2_PROXY_REDIRECT_URL: https://{{ provider.external_host }}/oauth2/callback OAUTH2_PROXY_COOKIE_SECRET: {{ cookie_secret }} - OAUTH2_PROXY_UPSTREAM: http://{{ provider.host }} + OAUTH2_PROXY_UPSTREAM: http://{{ provider.internal_host }}