From cdfb11549e5accd0f0ea31fd282800f8463913aa Mon Sep 17 00:00:00 2001 From: jiangweidong <1053570670@qq.com> Date: Thu, 30 May 2024 14:58:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3OAuth2=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=B7=B3=E8=BF=87=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=8D=E5=85=81=E8=AE=B8=E7=99=BB=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/oauth2/views.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/apps/authentication/backends/oauth2/views.py b/apps/authentication/backends/oauth2/views.py index 88f82dfa3..eaad1e1b0 100644 --- a/apps/authentication/backends/oauth2/views.py +++ b/apps/authentication/backends/oauth2/views.py @@ -4,7 +4,6 @@ from django.contrib import auth from django.http import HttpResponseRedirect from django.urls import reverse from django.utils.http import urlencode -from django.utils.translation import gettext_lazy as _ from authentication.utils import build_absolute_uri from authentication.views.mixins import FlashMessageMixin @@ -55,11 +54,7 @@ class OAuth2AuthCallbackView(View, FlashMessageMixin): logger.debug(log_prompt.format('Process authenticate')) user = authenticate(code=callback_params['code'], request=request) - if err_msg := getattr(request, 'error_message', ''): - login_url = reverse('authentication:login') + '?admin=1' - return self.get_failed_response(login_url, title=_('Authentication failed'), msg=err_msg) - - if user and user.is_valid: + if user: logger.debug(log_prompt.format('Login: {}'.format(user))) auth.login(self.request, user) logger.debug(log_prompt.format('Redirect')) @@ -68,8 +63,7 @@ class OAuth2AuthCallbackView(View, FlashMessageMixin): ) logger.debug(log_prompt.format('Redirect')) - # OAuth2 服务端认证成功, 但是用户被禁用了, 这时候需要调用服务端的logout - redirect_url = settings.AUTH_OAUTH2_PROVIDER_END_SESSION_ENDPOINT + redirect_url = settings.AUTH_OAUTH2_PROVIDER_END_SESSION_ENDPOINT or '/' return HttpResponseRedirect(redirect_url)