Troubleshooting Add Identity with External Provider with ASP.NET Core

Bervianto Leo Pratama - Mar 27 '23 - - Dev Community

Background

I want to add Microsoft Authentication to my ASP.NET Core app. Unfortunately, I have a bug when redirecting to the login page, which gives the wrong redirect URL. I use a load balancer and expect to get HTTPS scheme instead of HTTP.

Troubleshooting

I found this website, and that web redirects me to this page.

Solution

You will need to configure getting the Forwarded Header. You can use this code.

// ...
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders =
        ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});

// ...
var app = builder.Build();

app.UseForwardedHeaders();

// ...
Enter fullscreen mode Exit fullscreen mode

For more details, check here.

The solution is not enough for Linux and non-IIS! You will need this environment variable.

ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
Enter fullscreen mode Exit fullscreen mode

For more details, check here.

I only cover my case and the common one. For more details, check here.

Thank you

I hope that will help you a lot. Thanks for reading.

GIF Thanks

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player