I had the same issue once, i can provide you with some code that does the trick on my asp.net core 2.2 app.
If the code does not work, the key thing to google is asp.net core authentication behind reverse proxy (ignore any service fabric stuff).
In your ConfigureServices method
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
options.Authority = options.Authority + "/v2.0/";
options.TokenValidationParameters.ValidateIssuer = true;
});
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardLimit = null;
options.RequireHeaderSymmetry = false;
options.KnownNetworks.Clear(); // This is not really that smart - we should probably add a list of known proxies/networks
options.KnownProxies.Clear();
options.ForwardedHeaders = ForwardedHeaders.XForwardedHost |
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
And in your Configure method:
app.UseForwardedHeaders();
app.Use((context, next) =>
{
var fabricServiceNinja = Environment.GetEnvironmentVariable("SOMEENVIRONMENTVAR");
var fabricServiceUri = new Uri(fabricServiceNinja);
var servicePathBase = fabricServiceUri.AbsolutePath;
context.Request.PathBase = new PathString(servicePathBase);
return next();
});