google / oauth2l

oauth2l ("oauth tool") is a simple CLI for interacting with Google API authentication.
Apache License 2.0
643 stars 81 forks source link

Cannot generate refresh token with web app credentials - silent shut down. #166

Closed eKulshan closed 5 months ago

eKulshan commented 5 months ago

I'm folowing these guide trying to setup google ads api for my app.

When I run: oauth2l fetch --credentials credentials.json --scope adwords --output_format refresh_token I'm getting url for user to auth, but after consent given, user redirected to url listed in credentials redirect_uri and cli shuts down without showing the response. Contrary to #162 I'm not getting any errors, cli just stops without any result output to the console.

Solution was same as for #162 - generate desktop credentials instead of for web app. I've struggled to narrow down problem as I was not getting any errors.

Why web credentials not working? Well it's working partially, cause user getting redirected after consent screen and code is present in redirected url. There is just no follow up to getting refresh_token with that code.

Maybe good thing to do, is to add disclaimer in docs - that you need desktop credentials fro cli to work?

andyrzhao commented 5 months ago

Thanks for the suggestion. Yes, adding a disclaimer is long overdue - I will take a look to see if I can do so today. For some more context: "Web credentials" from cloud console is intended for web-apps that requires redirect to specific web URL for handling the auth. OAuth2l only works with "Desktop credentials" from cloud console which is intended to redirect to localhost for completing the auth process (oauth2l creates a temporary server to listen on localhost for the redirect).

andyrzhao commented 5 months ago

Documented in: https://github.com/google/oauth2l/pull/167