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 Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay