I run some CLI python code from the cloud terminal.
The code calls "google_auth_oauthlib" library.
auth_flow = flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file=client_secret_json_file_fath, scopes=scopes)
auth_flow.run_local_server()
I get in the cloud terminal an authentication url to click on. I pass the consent screen and I'm redirected to a localhost in the browser, which obviously cannot be resolved.
How can I get the secrets from google-cloud terminal?

What you should do is something like this.
If you run this code on your machine once. It will store the refresh token in the user_tokens file. then you can upload it to your cloud server and when it runs it will use that token file.
although it would probably be easer to use a service account if you can.