设为首页 加入收藏

TOP

第25章 退出外部身份提供商 - Identity Server 4 中文文档(v1.0.0)
2019-09-17 18:44:17 】 浏览:17
Tags:退出 外部 身份 提供商 Identity Server 中文 文档 v1.0.0

当用户注销 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地址

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#SuperSocket服务器的简易实现 下一篇第26章 联合注销 - Identity Serv..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目