c# - 将变量传递给 OpenId Connect RedirectToIdentityProvider/动态设置 acr 值
问题描述
在我的 Owin 启动中,我使用 OpenId 配置登录
在 Notifications -> RedirectToIdentityProvider 中,我需要根据用户输入设置提示和 acr 值。
由于配置是在启动期间完成的,并且那时我不知道用户输入,所以我不能在设置 openId 时只传递值。
触发登录时,我得到了我需要的用户输入,然后触发了 Notifications -> RedirectToIdentityProvider。这就是我需要设置提示和 acr 值的地方。但是我如何在这里传递它们?
public static void ConfigureCriiptoAuth(this IAppBuilder app, string loginMethod, string postLoginRedirectUri, string pLoginId = null)
{
string tenant = ConfigurationManager.AppSettings["CriiptoDomain"];
string clientId = ConfigurationManager.AppSettings["CriiptoId"];
string clientsecret = ConfigurationManager.AppSettings["CriiptoSecret"];
app.UseCookieAuthentication(new CookieAuthenticationOptions { });
var idOptions = new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
ClientSecret = clientsecret,
Authority = tenant,
ResponseType = "code",
ResponseMode = OpenIdConnectResponseMode.Query,
Caption = "Criipto",
Scope = OpenIdConnectScope.OpenIdProfile,
RedirectUri = "https://localhost:44357/",
SignInAsAuthenticationType = "Cookies",
RedeemCode = true,
SaveTokens = true,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = ctx => {
//HERE I NEED TO SET AcrValues and LoginHint,
//based on user inputs and not on values passed in at startup
ctx.ProtocolMessage.AcrValues = loginMethod;
if(pLoginId != null)
{
ctx.ProtocolMessage.LoginHint = pLoginId;
}
ctx.ProtocolMessage.RedirectUri = postLoginRedirectUri;
return Task.FromResult(0);
}
}
};
app.UseOpenIdConnectAuthentication(idOptions);
}
解决方案
推荐阅读
- python - 在 Python 中沿数轴(刻度线和脊椎)绘制分类变量
- javascript - HTML Canvas WebGL 上下文 readPixels 到 Array 返回零
- javascript - JS 在 codepen 中工作,但不在我的完整 HTML 文件的上下文中
- oracle - (Oracle)有条件地跳过扫描表(SKIP CTE conditionally)
- html - 在 CSS 中禁用视频
- java - 为什么这段代码的输出是 234 而不是 23?
- java - 可以以与二叉搜索树类似的方式使用 TreeSet 吗?
- javascript - 基于多个过滤器的过滤器阵列
- arrays - 使用函数返回数组
- go - 如何探索 go 包中的函数