-
Notifications
You must be signed in to change notification settings - Fork 4k
X-Forwarded-Proto with Azure and AWS #851
Comments
Changing our source code is never the best solution ;) Put a middleware in front that changes the scheme based on the incoming headers. |
I tried all the way that i can but no luck.. app.UseForwardedHeaders(new ForwardedHeadersOptions services.Configure(options => As BaseUrlMiddleware request.Scheme is still http only as we are not considering any of the xForwadedProto. HTTPS is configured on the load balancer not on the IIS server. |
I'd suggest getting it to work without IdentityServer and just use a plain ASP.NET Core MVC application. Once you have that working, then the same approach should work with IdentityServer. If it doesn't, then let us know. |
I use |
Here is what my startup file.. No luck on HTTPS
|
This issue resolved .. After installing/Upgrade the package "Microsoft.AspNetCore.HttpOverrides": "1.1.0" |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue / Steps to reproduce the problem
AWS load balancer is will always forward/redirect the http to https with HEADER AS X-Forwarded-Proto . This is causing the issue on document discovery with /.well-known/openid-configuration Even if the url is on https it will still return the value proto as http instead of https.
http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html#x-forwarded-proto
Solution
To Overcome this issue we need to change the BaseUrlMiddleware slightly
var origin = request.Scheme + "://" + request.Host.Value;
TO THE FOLLOWING
if (context.Request.IsHttps || // Handles https straight to the server
context.Request.Headers["X-Forwarded-Proto"] == "https" || // Handles an IIS or Azure/AWS passthrough
context.Request.Headers["X-Forwarded-Proto"].Contains("https"))
{
origin = "https://" + request.Host.Value;
}
else
{
origin = request.Scheme + "://" + request.Host.Value;
}
The text was updated successfully, but these errors were encountered: