我对如何使用它感到困惑。
我见过的大多数示例都将其指定为“ / signout-callback-oidc”。这似乎表明它在此过程中使用了OIDC中间件。如果我想返回特定的客户页面怎么办?
当我将IdentityServer的AutomaticRedirectAfterSignOut的AccountOptions.cs属性设置为true时,自动重定向不起作用。此外,在注销期间,我没有收到客户端的PostLogoutRedirectUri。
那么,该链接应该转到OIDC中间件,还是可以用于重定向到客户端?
McG*_*V10 13
您的客户端必须配置为请求回调到这些 URI 之一,作为客户端启动的注销流程的一部分。
IS4 clients can be configured with lists of allowable redirect URIs for both sign-in and sign-out, which I'm guessing is where you see /signout-callback-oidc -- if I remember right, either the docs or maybe the Quickstart code uses that, but there's nothing special about that particular URI name. (It isn't some OIDC standard, or a "well-known" name, or anything of that nature, as far as I know.)
The missing piece of the puzzle is to configure OIDC in the client application. You didn't mention what kind of application is on the client side, but in ASP.NET Core it's an option named SignedOutCallbackPath on the AddOpenIdConnect service:
services.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = appConfig["OidcAuthority"];
options.ClientId = appConfig["OidcClientId"];
options.ClientSecret = appConfig["OidcClientSecret"];
// etc
options.SignedOutCallbackPath = "/jake-says-goodbye";
});
Run Code Online (Sandbox Code Playgroud)
This causes the OIDC implementation to add a property to the sign-out request identifying that redirect URI. As long as your application properly identifies itself, as briefly mentioned in the docs here, and as long as /jake-says-goodbye is one of the approved post-logout redirect URIs on the IS4 side, you should get the callback you're expecting.
(I specifically mention "proper" identification because, based on github questions I've seen, it sounds like it might be more difficult to manage for a JS-based SPA client app versus whatever helpful things MVC does behind the scenes to manage server-to-server OIDC interaction. I can't speak to that as I've not had a need to implement any SPA clients with IS4 yet.)
问题是你必须设置一个非常具体的参数,以便PostLogoutRedirectUri在 IdentityServer 端不显示为 null,并且测试任何选项都会导致必须逐步通过大量方法来设置它,其中大多数仍然结果为空。由于我正在使用带有 IdentityServer4 的旧客户端(为了使 .NET 4.x webapps 通过 IdentityServer4 进行身份验证,无法轻松地将 .NET Core 用于这些项目 - 幸运的是 IdentityServer4 仍然与旧客户端代码兼容),该操作触发注销有两个相关的事情(你会发现大量的代码示例不适用于 .NET 4.x 中的 MVC):
使用signout()此示例 github 存储库(IdentityServer3 MVC Owin 示例客户端)中的方法:https://github.com/IdentityServer/IdentityServer3.Samples/blob/master/source/Clients/MVC%20OWIN%20Client/Controllers/HomeController.cs您可以通过视图中的按钮触发该操作。
如果您这样做,它将被客户端的 Owin 中间件拦截:https: //github.com/IdentityServer/IdentityServer3/issues/2687#issuecomment-194739035我没有使用存储的消息位,而是PostLogoutRedirectUri在这样 IdentityServer4 的LogoutRequest模型就不会删除同一段中的这一行:
n.ProtocolMessage.PostLogoutRedirectUri = "http://myredirectaddress/ActionToDoOnceReturned";
Run Code Online (Sandbox Code Playgroud)
您必须确保上述内容与PostLogoutRedirectUriIdentityServer 端的客户端配置中的客户端匹配,否则它将再次为空,并且您将在所有其他参数中错过它。例如,这些设置方法PostLogoutRedirectUri不起作用:
n.ProtocolMessage.SetParameter("PostLogoutRedirectURI", "some URL");
n.ProtocolMessage.SetParameter("PostLogoutUri", "another URL");
n.ProtocolMessage.SetParameter("PostLogoutRedirectUri", "yet another URL that's going to be ignored by IdentityServer4");
Run Code Online (Sandbox Code Playgroud)
从那里开始,您就可以开始比赛了,因为PostLogoutRedirectUri不再为空。还有一些注意事项:AccountOptions在 IdentityServer 控制器文件夹中查看。我AutomaticRedirectAfterSignout在那里设置为 true (这是由 Javascript 在 IdSrv 的最终注销页面中使用的 - 如果设置,脚本将用于PostLogoutRedirectUri将用户转发回客户端)。还有一个选项可以显示注销确认提示,如果您想实际显示该提示,请确保不要在 Owin 中设置 id 令牌提示(它就在我们设置 / 由PostLogoutRedirectUri注销请求触发的部分旁边) 。如果您执行这两件事,AccountServices.BuildLogoutViewModel当该方法调用它时,将向用户返回提示AccountController.logout()。感谢 aaronR 回答我关于该部分的其他问题:
IdentityServer4 logout(id 令牌提示告诉 IdentityServer 注销请求已获得授权,而不是恶意人员试图骚扰您的系统/注销用户,IdSrv 将要求用户确认如果没有提供)。
最后,如果您对注销时 IdentityServer 端发生的情况以及为什么它重复触发相同的方法感到困惑:
第一次从客户端的 Owin 中间件调用它(上面的代码在操作后触发Signout())。
它用于AccountService构建视图模型以返回给用户以进行注销确认。
用户在该页面上单击“是”会再次触发它。
它再次执行 Account 服务方法,这次将 bool 设置为 false,以显示注销确认。
它调用第二个注销方法,即带有传入的视图模型的方法。
这会触发外部身份提供商注销。
外部身份提供者将控制权返回给注销,导致它再次被调用,再次调用第二个注销方法。
最后,它会将用户返回到 IdentityServer 的注销页面。如果PostLogoutRedirectUri设置为AutomaticRedirectAfterSignOuttrue,则该页面上的 javascript 会自动将用户的浏览器转发到该页面。
由于要同时调试两个项目以及所有这些可能的设置重定向的方法(还必须匹配客户端/服务器端配置以免为空),因此很容易感到困惑。
| 归档时间: |
|
| 查看次数: |
7331 次 |
| 最近记录: |