使用应用程序网关的 Azure AD 重定向 URL

Mik*_*kus 7 azure-active-directory asp.net-core azure-application-gateway

我们有一个 ASP Core 2.0 应用程序,可以很好地与专用网络上的 Azure AD 配合使用。但是,我们一直在使用 Azure 应用程序网关,研究允许远程工作者等从外部访问应用程序的可能性。

我们已经在网关上注册了该应用程序,并且一旦使用 Azure AD 登录,匿名首页就可以通过ourapp.msappproxy.net. 但是,当(再次?)在应用程序中登录时,客户端被重定向回intervalServer/signin-oidc失败,因为它无法从外部访问。

虽然我怀疑这是解决方案的任何部分,但我尝试将重定向覆盖"CallbackPath": "/signin-oidc", 到绝对路径,ourapp.msappproxy.net/signin-oidc但我似乎无法弄清楚如何。更改 Azure 门户中的回复 URL 也无济于事(虽然我怀疑它会不会,但这只是为了验证,对吗?)。

我似乎无法在此特定情况下找到任何有关此的指导,因此很受欢迎。否则,我会思考以下问题:

1,如果我可以将重定向更改为ourapp.msappproxy.net/signin-oidc,是否可以解决登录问题?

2,我什至需要额外的登录步骤,还是应该更改应用程序以接受AzureAppProxyUserSessionCookieAzureAppProxyAccessCookie?(如果这甚至是一种选择?)

Mik*_*kus 5

感谢评论中的 rfcdejong 让我走上正轨。在我们的例子中,我可以通过覆盖OnRedirectToIdentityProvider事件并提供代理 URL 来将 Azure AD 与 Azure 应用程序网关结合使用ConfigureServices

services.AddAuthentication(...)
          .AddOpenIdConnect(options =>
         {
           options.ClientId = Configuration["Authentication:AzureAD:ClientId"];
           options.Authority = Configuration["Authentication:AzureAd:Authority"];
           options.CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"];

           if (IsProduction) // So that I can use the original redirect to localhost in development
           {
             Task RedirectToIdentityProvider(RedirectContext ctx)
             {
               ctx.ProtocolMessage.RedirectUri = "https://ourapp.msappproxy.net/signin-oidc";
               return Task.FromResult(0);
             }

             options.Events = new OpenIdConnectEvents
             {
               OnRedirectToIdentityProvider = RedirectToIdentityProvider
             };
           }
          })
Run Code Online (Sandbox Code Playgroud)

返回 URI 需要配置为与 Azure 门户中的应用程序匹配。还需要分配用户,但内部应用程序现在可以在任何地方使用,无需直接访问服务器。