当前位置: 移动技术网 > IT编程>开发语言>.net > 第25章 退出外部身份提供商 - Identity Server 4 中文文档(v1.0.0)

第25章 退出外部身份提供商 - Identity Server 4 中文文档(v1.0.0)

2019年04月28日  | 移动技术网IT编程  | 我要评论

男人帮杂志,沙尘下的传奇,鹏程狗友

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网