Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Identityserver4 IdentityServer/OWIN:注销后客户端未重定向到登录页_Identityserver4_Identityserver3_Owin Middleware - Fatal编程技术网

Identityserver4 IdentityServer/OWIN:注销后客户端未重定向到登录页

Identityserver4 IdentityServer/OWIN:注销后客户端未重定向到登录页,identityserver4,identityserver3,owin-middleware,Identityserver4,Identityserver3,Owin Middleware,我有一个新的IdP,它实现了IdentityServer4(.NET Core)。我正在使用它为MVC5客户端应用程序提供SSO/Cookie身份验证/授权。由于客户端应用程序不是.NET Core,因此我使用IdentityServer3和Microsoft.Owin nugets进行集成。将.NET核心和.NET这样混合在一起的例子并不多,但也有一些,我已经尽了最大的努力使其发挥作用。以下是每个配置的源代码: IdentityServer4(.NET Core,主要基于此): 我的客户(MV

我有一个新的IdP,它实现了IdentityServer4(.NET Core)。我正在使用它为MVC5客户端应用程序提供SSO/Cookie身份验证/授权。由于客户端应用程序不是.NET Core,因此我使用IdentityServer3和Microsoft.Owin nugets进行集成。将.NET核心和.NET这样混合在一起的例子并不多,但也有一些,我已经尽了最大的努力使其发挥作用。以下是每个配置的源代码:

IdentityServer4(.NET Core,主要基于此):

我的客户(MVC5):

注销大部分工作正常。我遇到的问题是重定向回登录页面,以便最终用户可以通过此处突出显示的链接再次登录到他们刚刚注销的客户端:
RedirectUri在配置的两侧(IdP和客户端)都正确配置,并且在视图中设置了超链接的href值(如图所示),但该URL还需要附加一个名为“state”的查询参数,以便它知道要重新登录到哪个应用程序(例如,在没有“state”参数的情况下单击此链接会得到404)。我遇到的问题是,我无法在“我的客户机”中获取/设置此“状态”值

从我读到的所有内容来看,您可以通过调用
n.OwinContext.Environment.GetSignOutMessageId()
来获得它,实际上它只是在封面下调用
n.OwinContext.Request.Query.get(“id”)
,但它总是返回null。知道为什么返回空值吗??
谢谢大家!

我所描述的大部分内容都记录在这里:使用
postlogutredirecturi=”http://localhost:5002
用于客户端配置中的MVC客户端,以及在MVC5客户端启动中使用相同的配置。cs OpenId Connect authentication configurations。谢谢。尝试此操作后,无效。
new Client()
{
    ClientId = "myClientId",
    ClientName = "My Client",
    ClientSecrets =
    {
        new Secret("secret".Sha256())
    },
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
    Enabled = true,
    RedirectUris = { "http://localhost:5002/signin-oidc" },
    PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },
    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
    }
}
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    Authority = "http://localhost:5000",
    ClientId = "myClientId",
    RedirectUri = "http://localhost:5002/signin-oidc",
    PostLogoutRedirectUri = "http://localhost:5002/signout-callback-oidc",
    ResponseType = "code id_token",
    SignInAsAuthenticationType = "Cookies",
    Scope = "openid",
    Notifications = new OpenIdConnectAuthenticationNotifications()
    {
        AuthorizationCodeReceived = n => {
            n.OwinContext.Response.Cookies.Append("stored_id_token", n.ProtocolMessage.IdToken);
            return Task.FromResult(0);
        },
        RedirectToIdentityProvider = n => {
            if (n.ProtocolMessage.RequestType == Microsoft.IdentityModel.Protocols.OpenIdConnectRequestType.LogoutRequest)
            {
                var idTokenHint = n.Request.Cookies["stored_id_token"];
                if (idTokenHint != null)
                {
                    n.ProtocolMessage.IdTokenHint = idTokenHint;
                    var signOutMessageId = n.OwinContext.Environment.GetSignOutMessageId();  // returns NULL!
                    //var signOutMessageId = n.OwinContext.Request.Query.Get("id");  // same thing as line above
                    if (signOutMessageId != null)
                    {
                        n.ProtocolMessage.State = signOutMessageId;
                    }
                }
            }
            return Task.FromResult(0);
        }
    }
});