Azure AD身份验证redirect_uri在Linux托管(Cloud Foundry)ASP.NET Core 2.2应用程序上未使用https

问题描述 投票:0回答:1

我有一个ASP.NET Core应用程序托管在SAP Cloud环境(Cloud-Foundry)中的linux容器上。

我正在使用Microsoft.AspNetCore.Authentication.AzureAD.UI库实现Azure AD身份验证。

认证失败,因为无论我最初使用什么协议访问Web应用程序,它都会使用redirect_uri协议生成http

此操作失败,因为它与Azure中应用程序注册中定义的https URL不匹配。

AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application

在选项中,您可以传入CallbackPath,但这仅接受相对路径(必须以/开头)。否则,它来自基于redirect_url自动生成的scheme, host, port and path extracted from the current request

我不了解的是,即使我用https直接在浏览器中访问应用程序,它仍然在redirect_uri中使用http。

我猜潜在的问题是Cloud Foundry中托管的应用程序接受HTTP请求。

这是我实现Azure AD身份验证的代码部分。

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
        .AddAzureAD(options => Configuration.Bind("Authentication:AzureAD", options));

services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
   {
       options.Authority = options.Authority + "/v2.0";            // Microsoft identity platform
       options.TokenValidationParameters.ValidateIssuer = true;   
   });


 app.UseHsts();
 app.UseHttpsRedirection();


  "Authentication": {
    "AzureAD": {
      "Instance": "https://login.microsoftonline.com/",
      "ClientId": "{app-application-id}",
      "TenantId": "{my-tenant-id}"
    }
  }
authentication asp.net-core https azure-active-directory cloudfoundry
1个回答
0
投票

您的问题类似于this one。区别在于您将应用程序部署在cloudfoundry中,另一人将应用程序部署在Azure Web应用程序中。

如果您的应用程序被迫使用https,则可以简单地强制redirect_uri使用https

如果您想使用HTTP和https都可以使用的通用解决方案(前提是您已经在Azure门户中将HTTP和https配置为重定向URL,则可以尝试在标头中找到真实的原型。

© www.soinside.com 2019 - 2024. All rights reserved.