gpt4 book ai didi

azure - 如何在.net core 2应用程序中从 Controller 设置OpenIdConnect选项提示="login"?

转载 作者:行者123 更新时间:2023-12-01 16:29:52 25 4
gpt4 key购买 nike

我正在使用 .net core 2 应用程序,并已在 Startup.cs 的 ConfigureServices 方法中将 OpenIDConnect 选项提示参数设置为同意

.AddOpenIdConnect(options =>
{
options.prompt ="consent";
}

但在初始登录页面中,我只想使用提示“login”而不同意屏幕。

在 Controller 页面

            return Challenge(
new AuthenticationProperties { RedirectUri =
Url.Action("Index") },
OpenIdConnectDefaults.AuthenticationScheme);

有什么方法可以将提示参数更改为从 Controller “登录”。在之前的版本中,我们可以使用 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;
}
};

它会在项目中查找是否有给定的提示值,如果有,则用该值替换现有值。

关于azure - 如何在.net core 2应用程序中从 Controller 设置OpenIdConnect选项提示="login"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50036780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com