首页 > 解决方案 > 当您在回调页面中并且用户想要取消注册时如何从外部提供商注销

问题描述

当您在回调页面中并且用户想要取消注册时如何从 Saml 外部提供商注销

注意:用户尚未注册,他只是输入外部提供商凭据并重定向到我的 IDP 以输入附加数据,我想添加操作以能够注销并取消注册过程。

注销代码

var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

        if (User?.Identity.IsAuthenticated == true)
        {
            // delete local authentication cookie
            await HttpContext.SignOutAsync();

            // raise the logout event
            await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
        }

        // check if we need to trigger sign-out at an upstream identity provider
        if (vm.TriggerExternalSignout)
        {
            // build a return URL so the upstream provider will redirect back
            // to us after the user has logged out. this allows us to then
            // complete our single sign-out processing.
            string url = Url.Action("Logout", "Account", new { Area = "Identity", logoutId = vm.LogoutId });

            // this triggers a redirect to the external provider for sign-out
            return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
        }


        return RedirectToPage("Login");

标签: asp.net-coreidentityserver4asp.net-core-identitysustainsys-saml2

解决方案


答案只是在当前上下文中设置用户,因此 saml2 可以读取所需的数据以进行重定向

Request.HttpContext.User = info.Principal;

推荐阅读