【发布时间】:2021-06-02 05:23:22
【问题描述】:
我有一个在 ASP.Net Core 3.1 中运行的 IdentityServer4 服务器(使用脚手架的 ASP.Net Core Identity)并验证我的单独 ASP.Net Core 3.1 Web 应用程序的用户。
我的问题在于注销,其中 IdentiyServer 注销上下文未反映在客户端定义的参数。
设置如下: 客户端的注销控制器方法结束如下:
var ap = new AuthenticationProperties();
ap.Parameters.Add("Reason", reason);
ap.Parameters.Add("TenantId", profileId.ToString());
return SignOut(ap, CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme);
我有一个这样定义的自定义 OpenIdConnectEvents 类:
public class CustomOpenIdConnectEvents : OpenIdConnectEvents
{
public override async Task RedirectToIdentityProviderForSignOut(RedirectContext context)
{
await base.RedirectToIdentityProviderForSignOut(context);
//a breakpoint on the above line confirms that the context.Properties.Parameters contains the values defined in the Controller logout method
}
}
在客户端的Startup.cs中挂接如下:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
//irrelevant cookie options here
})
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.EventsType = typeof(CustomOpenIdConnectEvents);
//other option settings here
});
在 IdentityServer 上,Logout Page 被调用,OnGet() 方法如下所示:
public async Task<IActionResult> OnGet()
{
var context = await _interaction.GetLogoutContextAsync(logoutId);
//at this point I expect context.Parameters to reflect the parameters sent from the client, but the .Parameters is empty.
//other code
}
为什么OIDC Client 端定义的Parameters 没有传递给OIDC Server?我错过了什么? (顺便说一句,在客户端上,我也尝试填充 .Items 属性而不是 .Parameters 属性,但没有任何区别)
【问题讨论】:
-
我显然在我的方法中遗漏了一些基本的东西,因为我已经设法在 IdentityServer4 QuickStart 2 上复制了这个问题。将做进一步的调查并恢复。
-
我明白了!添加解决方案作为答案!
标签: asp.net-core identityserver4 openid-connect