I know this question is OLD, but I I stumbled on this problem today and I want to share how I resolved it.
My organization has a standard development environment setup built on top of docker that uses <app-name>.localhost for the local apps, so the apps always are in "the root" of the web address.
To resolve this, I patched this setup to use a custom callback URL (And I registered it i the Google Console for the app):
http://localhost/login-with-google.php/<app-name>/<app-url-callback-path>
In this PHP file, I assembled the original intended URL based on the <app-name> and appended the query string provided by Google and redirected to the original callback URL.
Worked like a charm!