zquestz / omniauth-google-oauth2

Oauth2 strategy for Google
1.45k stars 413 forks source link

Output granted scopes in credentials block of the auth hash #420

Closed Envek closed 2 years ago

Envek commented 2 years ago

Google recommends to use Incremental authorization and request scopes only when needed. And there is include_granted_scopes option to enable this mode. And it works nice!

However, now it is hard to figure out whether user already has been granted required scopes or not yet, because there is no information about it in the auth hash. In this pull request I'm trying to solve this problem.

Luckily, there is API for that: tokeninfo endpoint (however scope isn't documented here, but documented in NodeJS API, I found info about it here and in my experiments it always return list of granted scopes even if token was acquired without using include_granted_scopes). And more luckily, omniauth-google-oauth2 is already using it for token validation!

So I added spec for credentials section of Auth hash (there wasn't one) and added output scope there as it is present in tokeninfo output.

zquestz commented 2 years ago

Looks great, thanks for the contribution!

Envek commented 2 years ago

Thank you for merging!

It would be lovely if you release a new version with all the goodies accumulated since last release.

zquestz commented 2 years ago

Done. 1.0.1 is out. =)