在使用旧版 IAM 的当前系统中,我们实现了一个继承自
ModelViewSet
的类,具有登录和注销功能。在旧版 IAM 中,注销时不需要获取 name_id
和 session_index
。因此,我们可以绕过acs
(又名assertion_consumer_service)来获取这些信息并直接退出。
现在,部署了新的 IAM 系统,我们需要扩展当前的实现以支持登录和注销(以及 acs)。
name_id
和session_index
应在LogoutRequest
中提供。鉴于我们有不同的 URL 集
如何更新以下代码以支持acs的回调,以便保存
name_id
和session_index
?
urls.py
router = DefaultRouter()
router.register("saml2/account", Saml2AccountView, basename="account")
urlpatterns = [
url("", include(router.urls)),
]
views.py
class Saml2AccountView(viewsets.ModelViewSet):
@action(detail=False, methods=['get'])
def login(self, request, *args, **kwargs):
# implement the login function
@action(detail=False, methods=['get'])
def logout(self, request, *args, **kwargs):
# implement the logout function
注意:我们使用 https://pypi.org/project/django-saml2-auth/ 进行登录/注销的 SAML 实现。
请尝试在
Saml2AccountView
类中添加以下方法:
class Saml2AccountView(viewsets.ModelViewSet):
@action(detail=False, methods=['get'])
def acs(request, *args, **kwargs):
# implement the acs function
并在
urls.py
中添加以下内容:
urlpatterns = [
path("saml2/account", Saml2AccountView.acs),
]