我正在努力在 Identity Server 4 服务中实现模拟功能。我知道有很多人反对以我想要的方式实现它,但我确实需要完全重定向回 SSO 服务器才能生成新的声明列表。被模拟的用户将拥有一组完全不同的规则作为声明与他们关联,因此它必须来自 IdSrvr。
我已经通读了https://github.com/IdentityServer/IdentityServer4/issues/853以及IdentityServer4 - 如何实现模拟
这是我到目前为止所尝试的,我们在 Identity Server 3 中使用 ACR 值和 Pre-Auth 完美地做到了这一点,甚至在 UserService 上也是如此。
我从身份服务器的客户端之一调用此控制器方法:
public IActionResult Impersonate(string userIdToImpersonate, string redirectUri)
{
return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties(){RedirectUri = redirectUri, Items = { {"acr_values", $"userIdToImpersonate:{userIdToImpersonate}"}}});
}
Run Code Online (Sandbox Code Playgroud)
这是我的 OnRedirectToProvider:
OnRedirectToIdentityProvider = context =>
{
if (context.Properties.Items.ContainsKey("acr_values"))
{
context.ProtocolMessage.AcrValues = context.Properties.Items["acr_values"].ToString();
}
return Task.CompletedTask;
}
Run Code Online (Sandbox Code Playgroud)
这是我开始迷路的地方,目前,我已经从AuthorizeInteractionResponseGenerator类继承并实现了我自己的覆盖 ProcessLoginAsync (这是我能找到的唯一接近 pre-auth 事件之前的事件)
protected override async Task<InteractionResponse> ProcessLoginAsync(ValidatedAuthorizeRequest request)
{
if (!request.IsOpenIdRequest) return …Run Code Online (Sandbox Code Playgroud)