【发布时间】:2018-04-05 16:29:55
【问题描述】:
我正在尝试构建一个不允许访问匿名用户的 ASP.NET MVC 应用程序(除了要显示给不允许使用该应用程序的经过身份验证的用户的自定义 URL) .
现在,我已在 azure 门户 (portal.azure.com) 中注册了我的应用,并且我想使用多个 URL。我添加了两个条目:
我正在使用以下代码在启动时配置身份验证:
public void ConfigureAuth(IAppBuilder app) {
app.SetDefaultSignInAsAuthenticationType(
CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions {
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications {
SecurityTokenValidated = VerificaUtilizadorAutenticado,
AuthenticationFailed = TrataErroAutenticacao
}
});
}
一切似乎都运行良好,但在发布应用程序后,我似乎只能使用其中一个 URI。我已经搜索过,似乎我可以使用 OpenIdConnectAuthenticationOptions 的 RedirectUri 属性来设置回复网址。因此,我尝试将其添加到设置中:
RedirectUri = "https://localhost/test",
不幸的是,这样做会破坏一切,并且浏览器会卡在我的应用程序和 MS 的登录页面之间。由于用户已登录,它将用户重定向回我的应用程序。但是,设置 RedirectUri 属性似乎不会生成应用的身份验证 cookie,因此会将用户发送回登录页面。
如果我删除 RedirectUri,我会被重定向到 https://www.test.com 站点,即使我正在尝试访问 https://localhost/test 网络应用程序。
我不确定是什么,但我遗漏了一些东西......有人可以帮忙吗?
谢谢。
路易斯
【问题讨论】:
-
能否分享一下用户登录界面的网址。如果您做的正确,该网址中应该有一个查询字符串参数,例如:
&redirect_uri=https://localhost/test. -
你好,肖恩。它没有被设置。没有redirect_uri参数...似乎它总是会重定向到第一个url...
标签: asp.net-mvc azure-active-directory openid-connect