How setup OpenId redirect uri in .NET Core 5 behind reverse proxy or loadbalance

248 views Asked by At

I developed an app in .NET Core 5 using the OpenIdConnect library (6.0.12.0). On the Azure portal I have correctly configured the redirect uri with https protocol. I have 2 endpoints set up pointing to localhost and production url.

However, the production URL is under reverse proxy. When I try to access the account, I am redirected to the binding set on the IIS (e.g. https://10.20.0.12:666/signin-oidc) and not to the URL managed by the reverse proxy: https://example.com/signin-oidc.

This is part of my code:

public void ConfigureServices(IServiceCollection services)
{
    var initialScopes = Configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');

    services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
        .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
            .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
                .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
                .AddInMemoryTokenCaches();

I try to set :

        services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
        {
            options.Events.OnRedirectToIdentityProvider = async context =>
            {
                context.ProtocolMessage.RedirectUri = "https://example.com/signin-oidc";
                await Task.FromResult(0);
            };
        });

I was looking for a complete example, can anyone help me?

0

There are 0 answers