Our ASP .Net Core (Razor) application is hosted in AWS and placed after a LoadBalancer (https). I know there is bug where urls are always unsecure with LoadBalancer. A rewrite rule was intregrated like described here: https://stackoverflow.com/a/46719766/3835956
But we are using the Azure Authentication to connect to our Active Directory and the forwarding (reply url) will always redirect to an unsecure http address. Okay, the url will be rewritten to https but for a short time the http address is called and the process is unsecure. I have to add the url with http and https to the list of reply urls in the Azure Application properties to log in.
The authentication is configured this way:
public void ConfigureServices(IServiceCollection services)
{
[...]
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.AddMvc(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
[...]
// Fix for AWS LoadBalancer to rewrite url back to https
// https://stackoverflow.com/a/46719766/3835956
var options = new RewriteOptions()
.AddRedirectToProxiedHttps()
.AddRedirect("(.*)/$", "$1"); // remove trailing slash
app.UseRewriter(options);
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSession();
app.UseAuthentication();
app.UseMvc();
}
The list of reply urls in Azure Application is for now:
Is there a trick to point Azure to the correct reply url? Thanks alot.
Update 1:
The appsettings.json looks like this:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "domain.com",
"TenantId": "abc-123",
"ClientId": "abc-123",
"CallbackPath": "/signin-oidc"
},
[...]
"AllowedHosts": "*"
}