Error on Auth0 redirect urls (redirect URI is wrong) with Nginx reverse proxy

Viewed 78

We are using Auth0 for authentication and NGINX for reverse proxy.

com.auth0.AuthenticationController is used at backend for the login and we updated all the setting at auth0 application and added these urls (http://localhost:8888, http://localhost:9999 ) to allowed callback urls list.

Nginx reverse proxy configuration

  server {
      listen       8888;
      server_name  localhost;
        
      location = /login {
          proxy_pass http://localhost:9999/login;
      }
  }

As per the above code when nginx gets login request it redirects it to http://localhost:9999/login

The service running at localhost:9999 is trying to get com.auth0.Token using the auth code

authenticationController.handle(request, response); 

but following exception is thrown.

The redirect URI is wrong. You sent http://localhost:9999, and we expected http://localhost:8888

Note: It is telling us that while creating the secret code at Auth0 we have provided http://localhost:8888 as redirect_uri, but trying to access the token using http://localhost:9999

How to tell the Auth0 server that it is proxied url?

1 Answers
server {
      listen       8888;
      server_name  localhost;
        
      location = /login {
    
          proxy_set_header Host $http_host;
          proxy_pass http://localhost:9999/login;
      }
  }

The code started working when we added the following line to nginx configuration.

proxy_set_header Host $http_host;

Related