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

  • 相关阅读:
    pytorch实现rnn并且对mnist进行分类
    python中的list按照某一列进行排序的方法
    pytorch实现style transfer
    Pytorch基本变量类型FloatTensor与Variable
    Linux上统计文件夹下文件个数以及目录个数
    python调用caffe实现预测
    python调用caffe环境配置
    JS实现唤起手机APP应用,如果本地没有则跳转到下载地址
    PHP开发中使用的工具
    Linux安装redis服务
  • 原文地址:https://www.cnblogs.com/thinksjay/p/10779075.html
Copyright © 2011-2022 走看看