我有一个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
,但这仅接受相对路径(必须以/开头)。
否则,它来自基于scheme,host,port and path extracted from the current request自动生成的redirect_url
。
我不了解的是,即使我使用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}"
}
}