Last Updated: May 16, 2022
·
18.53K
· adambird

Avoid 'Invalid Credentials' with Google OAuth2

I was struggling setting up OAuth2 authorisation to Google and the problem was down to the scope I was requesting.

I requested https://www.googleapis.com/auth/calendar in order to access the Calendar API on behalf of the user but was receiving

"reason": "authError",
"message": "Invalid Credentials"

Turns out you also have to request the https://www.googleapis.com/auth/userinfo.email scope as well as the scopes you're interested in. Google returns the email in the credentials hash and thus, I believe, if you haven't requested access to it you can't read it.

5 Responses
Add your response

If you are using https://github.com/zquestz/omniauth-google-oauth2 make sure to follow the note in README.
"You must enable the "Contacts API" and "Google+ API" via the Google API console."

This fixed the 'Could not authenticate you from GoogleOauth2 because "Invalid credentials".' problem for me.

over 1 year ago ·

Thanks abhishek77in! You saved me lots of trouble.

over 1 year ago ·

Thank you! This solved my problem.

over 1 year ago ·

Thanks for sharing.

over 1 year ago ·

Thanks for sharing this information...

over 1 year ago ·