DEV Community

Cover image for Troubleshooting Add Identity with External Provider with ASP.NET Core
Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on

2

Troubleshooting Add Identity with External Provider with ASP.NET Core

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up