honestbleeps / Reddit-Enhancement-Suite

Reddit Enhancement Suite
http://redditenhancementsuite.com
GNU General Public License v3.0
4.13k stars 881 forks source link

Specifying an G Suite email for googleAccount prevents getting `access_token` for backup #5269

Open YenForYang opened 3 years ago

YenForYang commented 3 years ago

"No token found in response" when googleAccount (googleLoginHint) is specified.

https://github.com/honestbleeps/Reddit-Enhancement-Suite/blob/5e2630b00a5837f9a59b8fbbefd8aa4acf136953/lib/environment/foreground/auth.js#L28-L41

I looked into the value of responseUrl when googleLoginHint is specified, and it's of the form:

https://accounts.google.com/o/oauth2/v2/auth?login_hint=<googleAccount>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.appdata&response_type=token&redirect_uri=https%3A%2F%2Fredditenhancementsuite.com%2Foauth&client_id=568759524377-nv0o2u4afuuulkfcjd7f6guf27qkevpt.apps.googleusercontent.com&hd=<googleAccount-domain>&as=...

which is missing the access_token parameter, rather than expected

https://redditenhancementsuite.com/oauth#access_token=...

But the returned responseUrl is valid, because when I punched responseUrl into the chrome browser (i.e. made an additional GET request) it performs a redirect to the correct address https://redditenhancementsuite.com/oauth#access_token=... which contains the access_token desired.

Perhaps another sendMessage should be added if the redirect_uri parameter exists, or if the responseUrl domain isn't redditenhancementsuite.

EDIT: Found a root cause (there may be more, I'm unsure)

It appears (from my tests) that an additional redirect is done when login_hint contains an email from a GSuite domain (rather than @yahoo, @gmail, etc.). For these emails, the hd parameter must be added in to prevent a second redirect.

In other words: domain: `https://accounts.google.com/signin/oauth?login_hint=${googleLoginHint} needs to be more like domain: `https://accounts.google.com/signin/oauth?login_hint=${googleLoginHint}&hd=${GSuiteDomain}.

The other option would be to support an arbitrary number of redirects, but it looks like the only thing the redirect does for now is add as and hd parameters. The as parameter doesn't seem to be necessary, but hd seems to be required.

Originally posted in https://github.com/honestbleeps/Reddit-Enhancement-Suite/issues/5212#issuecomment-751829160

abjugard commented 1 year ago

I'm seeing this in 5.22.15.