From 867ad94a302b15ed1f035ce07c97b43b2de96c68 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Wed, 17 Aug 2022 15:20:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=E5=9C=B0=E5=9D=80=20scheme=20?= =?UTF-8?q?=E5=8F=96=E5=80=BC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/authentication/utils.py b/apps/authentication/utils.py index a7f18648b..a0db9061c 100644 --- a/apps/authentication/utils.py +++ b/apps/authentication/utils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # import ipaddress -from urllib.parse import urljoin +from urllib.parse import urljoin, urlparse from django.conf import settings from django.utils.translation import ugettext_lazy as _ @@ -39,7 +39,11 @@ def build_absolute_uri(request, path=None): """ Build absolute redirect """ if path is None: path = '/' - redirect_uri = request.build_absolute_uri(path) + site_url = urlparse(settings.SITE_URL) + scheme = site_url.scheme or request.scheme + host = request.get_host() + url = f'{scheme}://{host}' + redirect_uri = urljoin(url, path) return redirect_uri @@ -50,6 +54,5 @@ def build_absolute_uri_for_oidc(request, path=None): if settings.BASE_SITE_URL: # OIDC 专用配置项 redirect_uri = urljoin(settings.BASE_SITE_URL, path) - else: - redirect_uri = request.build_absolute_uri(path) - return redirect_uri + return redirect_uri + return build_absolute_uri(request, path=path)