c# - 具有多个 OIDC 身份验证配置的 OWIN
问题描述
我的应用程序是 Asp.Net 4.7.2 Framework MVC。我想注册三个 OWIN OIDC Auth 配置并能够从中进行选择。
OpenIdConnectAuthenticationOptions oidcOptions1 = new OpenIdConnectAuthenticationOptions
{
ClientId = _oktaMvcOptions.ClientId,
ClientSecret = _oktaMvcOptions.ClientSecret,
Authority = _issuer,
RedirectUri = _oktaMvcOptions.RedirectUri,
ResponseType = OpenIdConnectResponseType.Code,
RedeemCode = true,
Scope = scopeString,
PostLogoutRedirectUri = _oktaMvcOptions.PostLogoutRedirectUri,
TokenValidationParameters = tokenValidationParameters,
SecurityTokenValidator = new StrictSecurityTokenValidator(),
AuthenticationMode = (_oktaMvcOptions.LoginMode == LoginMode.SelfHosted) ? AuthenticationMode.Passive : AuthenticationMode.Active,
SaveTokens = true,
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = BeforeRedirectToIdentityProviderAsync,
SecurityTokenValidated = SecurityTokenValidatedAsync,
AuthenticationFailed = _oktaMvcOptions.AuthenticationFailed,
},
};
OpenIdConnectAuthenticationOptions oidcOptions2 = new OpenIdConnectAuthenticationOptions{...};
OpenIdConnectAuthenticationOptions oidcOptions3 = new OpenIdConnectAuthenticationOptions{...};
在 Startup.cs 中,配置如下所示:
public void Configuration(IAppBuilder app)
{
app.UseOpenIdConnectAuthentication(oidcOptions1);
app.UseOpenIdConnectAuthentication(oidcOptions2);
app.UseOpenIdConnectAuthentication(oidcOptions3);
}
它们都是 OpenIdConnect 类型。当我打电话给挑战时:
HttpContext.GetOwinContext().Authentication.Challenge();
我如何告诉挑战使用 oidcOptions2 或 oidcOptions3?如何指定使用哪一个?
谢谢。
解决方案
没关系 - 很容易:
OpenIdConnectAuthenticationOptions oidcOptions1 = new OpenIdConnectAuthenticationOptions("first")
{
...
}
然后:
HttpContext.GetOwinContext().Authentication.Challenge("first");
推荐阅读
- graphql - 无法扩展远程 graphql 嵌套输入类型
- java - Hashmap相同值不同键比较
- node.js - 为什么我的自定义 process.env 在 dotenv 中不起作用?
- javascript - 我的代码和其他代码有什么区别?
- python-3.x - 加载泡菜 NotFittedError:TfidfVectorizer - 未安装词汇
- c - 在 C 中动态插入结构数组。退出,分段错误
- opencv - Opencv 的 Opencl 代码中的 WTV 用于图像调整大小
- html - 使用 Apache,如何在使用反向代理从另一台服务器返回的页面上解释 SSI?
- node.js - 应用正则表达式时避免创建空格
- ionic-framework - 如何在 Ionic App 中集成 TLS 套接字?