Browse Source

fix: 获得 oidc acs 等认证方式失败

pull/5270/head
xinwen 4 years ago committed by Jiangjie.Bai
parent
commit
8e12eebceb
  1. 6
      apps/audits/signals_handler.py
  2. 6
      apps/authentication/signals_handlers.py

6
apps/audits/signals_handler.py

@ -127,7 +127,11 @@ def on_audits_log_create(sender, instance=None, **kwargs):
def get_login_backend(request):
backend = request.session.get(BACKEND_SESSION_KEY, '')
backend = backend.rsplit('.', maxsplit=1)[-1]
return LOGIN_BACKEND.get(backend, '')
if backend in LOGIN_BACKEND:
return LOGIN_BACKEND[backend]
else:
logger.warn(f'LOGIN_BACKEND_NOT_FOUND: {backend}')
return ''
def generate_data(username, request):

6
apps/authentication/signals_handlers.py

@ -1,5 +1,6 @@
from importlib import import_module
from django.contrib.auth import BACKEND_SESSION_KEY
from django.conf import settings
from django.contrib.auth import user_logged_in
from django.core.cache import cache
@ -24,14 +25,17 @@ def on_user_auth_login_success(sender, user, request, **kwargs):
@receiver(openid_user_login_success)
def on_oidc_user_login_success(sender, request, user, **kwargs):
request.session[BACKEND_SESSION_KEY] = 'OIDCAuthCodeBackend'
post_auth_success.send(sender, user=user, request=request)
@receiver(openid_user_login_failed)
def on_oidc_user_login_failed(sender, username, request, reason, **kwargs):
request.session[BACKEND_SESSION_KEY] = 'OIDCAuthCodeBackend'
post_auth_failed.send(sender, username=username, request=request, reason=reason)
@receiver(cas_user_authenticated)
def on_cas_user_login_success(sender, request, user, **kwargs):
post_auth_success.send(sender, user=user, request=request)
request.session[BACKEND_SESSION_KEY] = 'CASBackend'
post_auth_success.send(sender, user=user, request=request)

Loading…
Cancel
Save