A bug in google.js
Issue Description
Hi @flovilmart, the Google authDataManager is validating access_tokens correctly but this part of the code from google.js causes "Google auth is invalid for this user."
This is what being return by https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=[my_access_token] :
{
"azp": "XXXXXX-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"aud": "XXXXXXX-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"sub": "XXXXXX19680970529269",
"scope": "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
"exp": "1477342432",
"expires_in": "3497",
"email": "[email protected]",
"email_verified": "true",
"access_type": "online"
}
How it should be done
I installed the latest version of Parse Server locally and modified the google.js by changing this
response.user_id == id to this response.sub == id and it works!
And here is my javascript code:
Parse.User.logInWith('google', {
authData: {
access_token: auth_data.authResponse.access_token,
id: userDetails.id
}
}).then(function (user) {
console.log('Hi ' + userDetails.first_name + ', you are signed in to Google.');
}, function (error) {
console.log(error);
});
@hslorenzo the code is actually how it should be checked given the documentation from Google:
https://developers.google.com/identity/protocols/OAuth2UserAgent#tokeninfo-validation
And then id_token validation...
https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint
I'M not sure why you get the result from id_token validation when passing it as access_token.
Aha!
I just found out that if you use v2 of oauth2 https://www.googleapis.com/oauth2/v2/tokeninfo?access_token it returns:
{
"issued_to": "xxx-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"audience": "xxx-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"user_id": "xxx",
"scope": "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
"expires_in": 679,
"email": "[email protected]",
"verified_email": true,
"access_type": "online"
}
But, v3 of oauth2 https://www.googleapis.com/oauth2/v3/tokeninfo?access_token it returns:
{
"azp": "XXXX-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"aud": "xxxx-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com",
"sub": "xxxx",
"scope": "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
"exp": "1477342432",
"expires_in": "461",
"email": "[email protected]",
"email_verified": "true",
"access_type": "online"
}
Both documentations refer to v3... which make no friggin sense!!! AND we're using V3
userid This field is only present if the profile scope was present in the request.
Seems that we need to check either of them in both cases.
The https://www.googleapis.com/auth/userinfo.profile is present in the request.
You are right. It makes no sense.
In docs the following response is given :
{
"audience":"8819981768.apps.googleusercontent.com",
"user_id":"123456789",
"scope":"profile email",
"expires_in":436
}
But in reality the API response is the following Endpoint: https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=ABCD1234
{ "aud": "XXXX-18qib66ako3jcr0ikaake9rlm2lhlqob.apps.googleusercontent.com", "sub": "12345", "access_type": "offline", "expires_in": "1465" "scope": "email profile",
some other extra fields
}
this is SO STUPID!!! THANKS GOOGLE!!!
I rues the solution is to check both params to prevent any further cluster fuck like that.