我希望用户从该客户端注销后将其重定向到同一客户端。因此,如果我说一台身份服务器上有5个客户端,那么我希望用户能够从一个客户端注销并在同一客户端上却注销。
我尝试过的一件事是在快速入门中在AccountController中使用PostLogoutRedirectUri,但该值始终为null。我发现的解决方法是手动设置PostLogoutRedirectUri,如果服务器上只有一个客户端,那么效果很好,但是如果我有多个客户端,则效果不是很好。有什么方法可以知道哪个客户端已“注销”吗?
public async Task<IActionResult> Logout(LogoutInputModel model)
{
// build a model so the logged out page knows what to display
var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);
if (User?.Identity.IsAuthenticated == true)
{
// delete local authentication cookie
await HttpContext.SignOutAsync();
// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
}
// 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);
}
vm.PostLogoutRedirectUri = "http://localhost:56582";
return Redirect(vm.PostLogoutRedirectUri);
}
我的客户
new Client
{
ClientId = "openIdConnectClient",
ClientName = "Implicit Client Application Name",
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"role",
"customAPI.write"
},
RedirectUris = new List<string>{ "http://localhost:56582/signin-oidc" },
PostLogoutRedirectUris = new List<string>{ "http://localhost:56582" },
// FrontChannelLogoutUri = "http://localhost:56582/signout-oidc"
}
参考方案
您不应该手动设置uri。实际上,IdentityServer示例中的默认注销方法可以正常工作。
尝试3_ImplicitFlowAuthentication示例项目时,您会看到PostLogoutRedirectUri
不为null,并且重定向有效(但不是自动进行的)。
您的情况下PostLogoutRedirectUri
是null
的原因可能是因为未保留id_token。确保在MvcClient.Startup中添加以下行:
options.SaveTokens = true;
这样会将令牌保留在cookie中。
为了自动重定向回客户端,请对示例代码进行一些调整。在IdentityServer AccountOptions中设置
AutomaticRedirectAfterSignOut = true;
在AccountController.Logout方法中,添加以下行:
if (vm.AutomaticRedirectAfterSignOut &&
!string.IsNullOrWhiteSpace(vm.PostLogoutRedirectUri))
return Redirect(vm.PostLogoutRedirectUri);
在最后一行之前:
return View("LoggedOut", vm);
当您再次运行该示例时,应该看到注销后用户现在自动返回到客户端。
单击选项卡链接时,请专注于每个引导选项卡中的First asp:textbox - javascript我是开发的新手,并开始开发简单的asp.net应用程序。我正在使用每个都有一些asp标签和文本框的bootstrap选项卡。单击该选项卡时,我要重点关注选项卡内容中的第一个文本框。我搜索了各种答案,但都是针对输入字段的(exp:输入type =“ text”)。找不到适用于ASP文本框的任何内容。任何帮助将不胜感激。谢谢 javascript参考方案 ASP…
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
ASP.NET-如何更改JSON序列化的方式? - javascript我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …
Asp.Net:在服务器端还原DropDownList的客户端SelectedItem - c#因此,我的页面上有一个dropDownList,其中包含数百个项目。用户可以通过在文本框中键入一些文本来过滤此DDL。然后对DDL进行相应的过滤(所有不包含输入文本的项目都将通过JavaScript删除)。然后,用户选择他的项目并按下按钮。通常,这将导致错误,因为DDL已更改并且ASP验证了PostBack数据。但是,使用EnableEventValidat…