Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication "Log" message should be printed to STDERR instead of STDOUT, to avoid breaking shell scripts which redirect output #169

Open
vorburger opened this issue Jun 16, 2024 · 5 comments
Assignees

Comments

@vorburger
Copy link
Member

I'm using (something more or less like) the following inside a bash script:

oauth2l curl --scope tasks.readonly --url https://tasks.googleapis.com/tasks/v1/users/@me/lists --credentials credz.json >task-lists.json

Every 15' or so, when I it launches the Web Browser login thing, to refresh the token, which is successful (!), that task-lists.json file is "broken", and I have to manually fix it, because instead of containing valid JSON, it starts with:

Your browser has been opened to visit:

 https://accounts.google.com/o/oauth2/auth?client_id=...

{
  "kind": "tasks#tasks",

This is because oauth2l writes both it's "real output" (JSON) as well as it's "diagnostics bla bla" to STDOUT.

IMHO, it would be better if "Your browser has been opened to visit:" and what not were written to STDERR instead of STDOUT?

Code to be changed from fmt.Println to fmt.Fprintln(os.Stderr, "...") is here

Would you welcome a PR fixing this?

@andyrzhao
Copy link
Collaborator

andyrzhao commented Dec 3, 2024

Hi there, thank you for your feedback! IMO, relying on a convention of writing diagnostics to STDERR and output to STDOUT will be hard to enforce longterm. In your particular case, I believe we can support a consentSettings.SilentOpenConsentPage to not print out the prompts - that would make the usage intention very clear. We could also support a "silent" setting at the top level, but that would require a complete overhaul in prompts and diagnostics (unlikely anyone will be able to get to that in the near future.) Let me know if you still need this feature. thanks!

@vorburger
Copy link
Member Author

@andyrzhao yeah I do still think such a feature could be quite useful for end-users.

@andyrzhao
Copy link
Collaborator

@vorburger, as our team does not currently have bandwidth to develop for oauth2l, please feel free to put up a PR to add "consentSettings.SilentOpenConsentPage" as proposed. Ulises was the original engineer who worked on consentSettings and can help review and merge in your PR. Thanks!

@jozsi
Copy link

jozsi commented Feb 11, 2025

Meanwhile, I have worked it around like this (it will remove everything until the first occurence of {):

oauth2l fetch --credentials ../client_secret.json --scope userinfo.email --output_format json | awk '/^{/{found=1} found' > oauth.json

@vorburger
Copy link
Member Author

@andyrzhao I personally currently don't use this frequently enough to be motivated to raise a PR.

@jozsi if this bothers you enough, I'm assuming the maintainers of this project would welcome a proposed PR from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants