Configuring OpenId and AspCore behind a load balancer

I currently have an asp.net Core application that uses OpenId Connect to authenticate using Google Accounts. When this application is deployed and sitting at the load balancer, it does not redirect to the login page, since it sets uri as http instead of https, it also sets uri redirection for openid server, as without https, is there any way to configure the settings so that it knows What should he use https?

+4
source share
1 answer

According to @Tratcher's comment, this was resolved by creating middleware that checks the X-Forwarded headers as follows:

app.Use(async (context, next) =>
{
  if (context.Request.Headers.ContainsKey("X-Forwarded-Proto") || 
      context.Request.Headers.ContainsKey("X-Forwarded-For"))
  {
      context.Request.Scheme = "https";
  }
  await next.Invoke();
});
+3
source

Source: https://habr.com/ru/post/1671358/


All Articles