Authentication Callback url http:// when using Cloudflare

Hello. I’m developing a new website using Dotnet Core in debian linux, proxying with nginx and configured with Cloudflare

the SDK is Auth0.AspNetCore.Authentication version 1.0.0
dotnet version 6.0.101
Debian 10

The authentication is working when I turn off proxy cache in Cloudflare DNS.
When I turn it on, the url for login is

https://XXXXX.us.auth0.com/authorize?client_id=NHQSfWqF9s5byKEYKEY444F80&redirect_uri=http%3A%2F%2Foligrid.net%2Fcallback&

The redirect_uri turn HTTP when cache is on and HTTPS when off.

Do you have some tips to do here ?

Nginx proxy configuration for headers ?

the website is https://oligrid.net

and the problem is I don’t want to callback in http://

Maybe today you love me :heartbeat:
It’s very easy just add in your nginx in location this line:

proxy_set_header Host oligrid.net

Like the image just add this line (dont delete your configuration just add this line)

1 Like

I forget and in your setup.cs add :

services.Configure(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;

});

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
add

app.UseForwardedHeaders();

Like this configuration:

        public void ConfigureServices(IServiceCollection services)
        {
    
            services.ConfigureSameSiteNoneCookies();

            services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;

});

            services.AddAuth0WebAppAuthentication(options =>
            {
                options.Domain = Configuration["Auth0:Domain"];
                options.ClientId = Configuration["Auth0:ClientId"];
            });

            services.AddControllersWithViews();
  
        }

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseForwardedHeaders();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseForwardedHeaders();
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseRouting();


            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
            });
        }

Yes ! Thank you very much.
Now it is working.

1 Like

Wooohooo thanks for sharing it with the rest of community @PowerUnix !