我正在使用 .net core 2 应用程序,并已将 OpenIDConnect 选项提示参数设置为在 Startup.cs 的 ConfigureServices 方法中同意
.AddOpenIdConnect(options =>
{
options.prompt ="consent";
}
但在初始登录页面中,我想在未经同意的情况下仅使用提示“登录”。
在控制器页面中
return Challenge(
new AuthenticationProperties { RedirectUri =
Url.Action("Index") },
OpenIdConnectDefaults.AuthenticationScheme);
有什么方法可以将提示参数更改为从控制器“登录”。在之前的版本中,我们可以使用 OwinContext 来完成此操作。
HttpContext.GetOwinContext().Environment.Add("Prompt","login");
如有任何帮助,我们将不胜感激,谢谢。
您可以使用Items
传递任意参数的属性:
var authenticationProperties = new AuthenticationProperties
{
RedirectUri = Url.Action("Index")
};
authenticationProperties.Items["prompt"] = "login";
return Challenge(
authenticationProperties,
OpenIdConnectDefaults.AuthenticationScheme);
然后你将不得不处理OnRedirectToIdentityProvider
事件,类似这样的:
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
if (context.Properties.Items.TryGetValue("prompt", out string prompt))
{
context.ProtocolMessage.Prompt = prompt;
}
return Task.CompletedTask;
}
};
它会在项目中查找是否有给定的提示值,如果有,则用该值替换现有值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)