【发布时间】:2019-04-26 23:09:25
【问题描述】:
我已将 AuthenticationMode 设置为被动并使用显式质询重定向到 azure 登录页面。
这很好用,但我需要一种编程方式来确定用户是否经过身份验证。我也想使用用户名,但在 HttpContext.User.Identity.IsAuthenticated 中不可用。
请告诉我从哪里可以得到这些信息?
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
AuthenticationType="a",
AuthenticationMode = AuthenticationMode.Passive,
MetadataAddress = String.Format(aadInstance2, tenant2, SignUpSignInPolicyId),
ClientId = clientId2,
RedirectUri = redirectUri2,
PostLogoutRedirectUri = postLogoutRedirectUri,
CallbackPath= new PathString("/Home/index"),
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "b",
AuthenticationMode = AuthenticationMode.Passive,
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
CallbackPath = new PathString("/Home/contact"),
});
public void Redirect1()
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, "b");
}
public void Redirect2()
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, "a");
}
【问题讨论】:
-
可以添加认证配置的代码吗?
-
已添加代码。
-
嗯,您的回调路径可能不应该与现有路由匹配。它们通常类似于
/oidc-callback。您确实需要为这两个中间件指定不同的。 -
我更改了回调路径,但 user.identity.IsAuthenticated 为 false。如果我将 AuthenticationMode 设置为 Active,它确实有效
标签: c# azure azure-active-directory