zoukankan      html  css  js  c++  java
  • 第25章 退出外部身份提供商

    当用户注销 IdentityServer并且他们使用外部身份提供程序登录时,可能会将其重定向到注销外部提供程序。并非所有外部提供商都支持注销,因为它取决于它们支持的协议和功能。

    要检测是否必须将用户重定向到外部身份提供程序以进行注销通常是通过使用idp在IdentityServer中发布到cookie中的声明来完成的。设置到此声明中的值是AuthenticationScheme相应的身份验证中间件。在签出时,咨询此声明以了解是否需要外部签出。

    由于正常注销工作流程已经需要清理和状态管理,因此将用户重定向到外部身份提供商是有问题的。然后,在IdentityServer完成正常注销和清理过程的唯一方法是从外部身份提供程序请求在注销后将用户重定向回IdentityServer。并非所有外部提供商都支持退出后重定向,因为它取决于它们支持的协议和功能。

    然后,注销的工作流程将撤消IdentityServer的身份验证cookie,然后重定向到请求注销后重定向的外部提供程序。退出后重定向应保持此处描述的必要签出状态(即logoutId参数值)。要在外部提供程序注销后重定向回IdentityServer,RedirectUri应该AuthenticationProperties在使用ASP.NET Core的SignOutAsyncAPI 时使用,例如:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Logout(LogoutInputModel model)
    {
        // build a model so the logged out page knows what to display
        var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);
    
        var user = HttpContext.User;
        if (user?.Identity.IsAuthenticated == true)
        {
            // delete local authentication cookie
            await HttpContext.SignOutAsync();
    
            // raise the logout event
            await _events.RaiseAsync(new UserLogoutSuccessEvent(user.GetSubjectId(), user.GetName()));
        }
    
        // 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", new { logoutId = vm.LogoutId });
    
            // this triggers a redirect to the external provider for sign-out
            return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
        }
    
        return View("LoggedOut", vm);
    }
    

    一旦用户退出外部提供程序然后重定向回来,IdentityServer的正常注销处理应该执行,这涉及处理logoutId和执行所有必要的清理。

    github地址

  • 相关阅读:
    笨笨的洪水堵截
    青蛙的约会
    扩展欧几里德
    windows上修改路由表
    怎样编写注册表文件
    win7启动文件修复
    word文档中的字号和磅的对应关系
    将Windows 7导航窗格中的收藏夹、库、家庭组、网络全部去掉
    DNS
    UTF-8 GBK GB2312 之间的区别和关系
  • 原文地址:https://www.cnblogs.com/thinksjay/p/10779075.html
Copyright © 2011-2022 走看看