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地址

  • 相关阅读:
    我是如何基于angular+requirejs+node做SPA项目架构的
    阿里云无线&前端团队是如何基于webpack实现前端工程化的
    angularjs源码分析之:angularjs执行流程
    你所必须掌握的三种异步编程方法callbacks,listeners,promise
    自从用了Less 编写css,你比以前更快了~
    对象的深浅拷贝
    throttle/debounce: 为你的cpu减减压(前端性能优化)
    jekyll : 使用github托管你的博客
    html5 drag api详解
    用setTimeout 代替 setInterval实时拉取数据
  • 原文地址:https://www.cnblogs.com/thinksjay/p/10779075.html
Copyright © 2011-2022 走看看