Skip to content

Google auth is invalid for this user. #4698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
josephkandi opened this issue Apr 4, 2018 · 31 comments
Closed

Google auth is invalid for this user. #4698

josephkandi opened this issue Apr 4, 2018 · 31 comments

Comments

@josephkandi
Copy link

josephkandi commented Apr 4, 2018

We use GitHub Issues for bugs.

If you have a non-bug question, ask on Stack Overflow or Server Fault:

If you have a vulnerability disclosure, please follow our policy available here https://github.com/parse-community/parse-server/blob/master/SECURITY.md

You may also search through existing issues before opening a new one: https://github.com/parse-community/parse-server/issues?utf8=%E2%9C%93&q=is%3Aissue

--- Please use this template. If you don't use this template, your issue may be closed without comment. ---

Issue Description

Am trying to login with Google. I have used the Google OAuth 2 Playground and got an access token. Am passing the access token in the authData as follows

{ "username": "josephkandi", "authData": { "google": { "id": "[email protected]" "access_token": "token-here" } } }

Steps to reproduce

My app is hosted on Heroku, so i have used the parse-server example, https://github.com/parse-community/parse-server-example.

I have updated my packages.json to the latest as follows :

"dependencies": { "express": "^4.16.3", "kerberos": "0.0.23", "parse": "^1.11.1", "parse-server": "^2.7.4" }

I use Postman and send a POST request to https://my-parse-server-url/parse/users/

Expected Results

Am supposed to get 201 created but instead i get the error :

{ "code": 101, "error": "Google auth is invalid for this user." }

Actual Outcome

What is happening instead.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.7.4
    • Operating System: Heroku
    • Hardware: Heroku
    • Localhost or remote server? heroku
  • Database

    • MongoDB version: mlab, Heroku addon
    • Storage engine: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? Heroku

Logs/Trace

2018-04-04T20:07:18.458649+00:00 app[web.1]: verbose: REQUEST for [POST] /parse/users/: { 2018-04-04T20:07:18.458670+00:00 app[web.1]: "username": "josephkandi", 2018-04-04T20:07:18.458672+00:00 app[web.1]: "authData": { 2018-04-04T20:07:18.458674+00:00 app[web.1]: "google": { 2018-04-04T20:07:18.458676+00:00 app[web.1]: "id": "myemail", 2018-04-04T20:07:18.458679+00:00 app[web.1]: "access_token": "ya29.GluTBbIljEVZ8ZuPfNZg0l8BaoylumMqMmkFLFpZ9msncMvKXWh_h2ofrDQ9I-qj0-CTSQyIWslepBwe1ygB_y0WzatkrnBO0UovdVwbv26iRFtYaf9gkn5omSvu" 2018-04-04T20:07:18.458681+00:00 app[web.1]: } 2018-04-04T20:07:18.458682+00:00 app[web.1]: } 2018-04-04T20:07:18.458685+00:00 app[web.1]: } method=POST, url=/parse/users/, host=parse.peruzal.com, connection=close, accept-encoding=gzip, cf-ipcountry=ZA, x-forwarded-for=41.145.73.111, 172.68.186.57, cf-ray=40666681aa3f8064-CPT, x-forwarded-proto=http, cf-visitor={"scheme":"https"}, x-parse-application-id=my-app-id, content-type=application/json, cache-control=no-cache, postman-token=ab113afa-78c2-4414-962d-ce51d03bddca, user-agent=PostmanRuntime/7.1.1, accept=*/*, cookie=__cfduid=d8327f1e50a2c7db19b3091e5f4b147501522793473, cf-connecting-ip=41.145.73.111, x-request-id=76657b5e-e223-4292-af15-249a8f75fb94, x-forwarded-port=80, via=1.1 vegur, connect-time=1, x-request-start=1522872438434, total-route-time=0, content-length=261, username=josephkandi, id=myemail, access_token=ya29.GluTBbIljEVZ8ZuPfNZg0l8BaoylumMqMmkFLFpZ9msncMvKXWh_h2ofrDQ9I-qj0-CTSQyIWslepBwe1ygB_y0WzatkrnBO0UovdVwbv26iRFtYaf9gkn5omSvu 2018-04-04T20:07:18.569037+00:00 app[web.1]: error: Error generating response. ParseError { code: 101, message: 'Google auth is invalid for this user.' } code=101, message=Google auth is invalid for this user. 2018-04-04T20:07:18.572271+00:00 app[web.1]: error: Google auth is invalid for this user. code=101, message=Google auth is invalid for this user. 2018-04-04T20:07:18.574979+00:00 heroku[router]: at=info method=POST path="/parse/users/" host=parse.peruzal.com request_id=76657b5e-e223-4292-af15-249a8f75fb94 fwd="41.145.73.111,172.68.186.57" dyno=web.1 connect=1ms service=138ms status=404 bytes=591 protocol=http

@flovilmart
Copy link
Contributor

What are you using for the id/access_token? How to you acquire them?

@josephkandi
Copy link
Author

I acquire them using the Google Oauth 2.0 Playground website, https://developers.google.com/oauthplayground/.

When i test this using the Playground on this url https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=token-here it works fine

@flovilmart
Copy link
Contributor

And the id corresponds the the acquired ID?

@josephkandi
Copy link
Author

The id is my email username. You dont acquire an id from that endpoint but you get the an id_token, is the id the id_token? I thought from code here

function validateAuthData(authData) { if (authData.id_token) { return validateIdToken(authData.id, authData.id_token); } else { return validateAuthToken(authData.id, authData.access_token).then(() => { // Validation with auth token worked return; }, () => { // Try with the id_token param return validateIdToken(authData.id, authData.access_token); }); } }

It check i passed in the id_token or the access_token. Clearly though using the id_token doesn't seem to work when testing with the Google OAuth 2 playground.

I will try get the access_token with code and see if that works. It probably should work first because my app have the Google App ID on the client side, and when i login, i need to authorize that. When i use playgrounds, am authorizing a different app.

This is the part i didnt understand how parse is working, for which app configured on google does it verifies the token?

@flovilmart
Copy link
Contributor

The id is this case is clearly not the email username, but the user id for the google services, provided by google after you make your oauth authentication calls.

If you have an id_token, you can pass id/id_token pair instead of id/access_token, both are supported

@josephkandi
Copy link
Author

Am using the client id from the Google Console API for the iOS app, and still nothing. I have decoded the id_token i got and its a valid oauth2 token.

I tried sending that and still i get the same error. Am getting a 404 response code with the error :

{ "code": 101, "error": "Google auth is invalid for this user." }

I have used the access token and still same error. I have run out things to test now.

@josephkandi
Copy link
Author

Using the app i can retrieve my profile details on this endpoint https://www.googleapis.com/oauth2/v2/userinfo using the access_token i get on the app. The same access token am unable to authenticate with parse to login a user.

@flovilmart
Copy link
Contributor

flovilmart commented Apr 4, 2018

Yes because you need to provide the user ID from google. As long as you pass the id as an email, this won’t work. As for how to acquire the id for the google user, check the google login documentation.

See: https://developers.google.com/identity/protocols/OAuth2

@josephkandi
Copy link
Author

josephkandi commented Apr 4, 2018

Am not passing the id as email, am using the client id from Google API console.

Using Postman, i can make the same request using the access token and get back the following :

{ "azp": "21547282892-gc6ih5922efrnpvlgh7fh25n40m3it7d.apps.googleusercontent.com", "aud": "21547282892-gc6ih5922efrnpvlgh7fh25n40m3it7d.apps.googleusercontent.com", "sub": "112694148092739840900", "scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me", "exp": "1522886440", "expires_in": "1212", "email": "[email protected]", "email_verified": "true", "access_type": "offline" }

Which is correct, but somehow the server returns a 404 not found when i use the same token to login with parse.

How can i debug this locally? I might just need to go through the code locally and put a break point and see whats really happening.

@josephkandi
Copy link
Author

Clearly the issue is not with the token. The token works as i have used it in two places, using Postman locally and on the Google OAuth 2 Playground. I have also decoded the id_token and its a valid jwt token. So those are valid and not the issue.

@flovilmart
Copy link
Contributor

As per the documentation, parse requires a user id that identifies uniquely your user in the scope of the google authentication. https://github.com/parse-community/parse-server/blob/master/src/Adapters/Auth/google.js#L8

In your case, given the response, you should probably pass the subvalue as the id:

id: "112694148092739840900",
access_token: access_token

@josephkandi
Copy link
Author

Still that does not work

@flovilmart
Copy link
Contributor

This should work, double check your parameters, id, id_token or access_token and make sure you pass the right values. I can assure you it works, as we use it in production currently.

@josephkandi
Copy link
Author

Nope, checked and re-checked. No joy. Why do i get a 404 not found from parse?

@flovilmart
Copy link
Contributor

what is your payload that you send?

@josephkandi
Copy link
Author

{ "username": "joey2", "authData": { "google": { "id": "2112694148092739840900", "access_token": "ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S" } } }

application/json

This works fine for Facebook

{ "username" : "josephk", "authData" : { "facebook": { "id": "127698748074950", "access_token": "EAADBB1OuCRsBAGP3kk4wxpC6UtnypMKub9ZArsbt9dAZBLLEQ92Iq1LUvtnASknxTZBebnPbJWu3Hd61JTQYw0ZCKwFbcU4Q85fTCkj2Twf0jvHossk04AZACO1AHH0SDPhxtZBTPEKdl8WRuVZB8giEuQLMmFB9uKFQTtNN34LNb8xElcqgFRZCv8k4ClIBS2T6vRb9LXOCif8DNIjRRNYu5sXLNbEPRooLpkwjJFb7oQaZCtYwZA0Mso", "expiration_date": "2018-04-05'T'00:00:00.000'Z'" } } }

@josephkandi
Copy link
Author

Logs from Heroku

2018-04-05T00:00:50.046836+00:00 app[web.1]: verbose: REQUEST for [POST] /parse/users/: { 2018-04-05T00:00:50.046853+00:00 app[web.1]: "username": "joey2", 2018-04-05T00:00:50.046856+00:00 app[web.1]: "authData": { 2018-04-05T00:00:50.046858+00:00 app[web.1]: "google": { 2018-04-05T00:00:50.046861+00:00 app[web.1]: "id": "2112694148092739840900", 2018-04-05T00:00:50.046868+00:00 app[web.1]: "access_token": "ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S" 2018-04-05T00:00:50.046870+00:00 app[web.1]: } 2018-04-05T00:00:50.046872+00:00 app[web.1]: } 2018-04-05T00:00:50.046876+00:00 app[web.1]: } method=POST, url=/parse/users/, host=parse.peruzal.com, connection=close, accept-encoding=gzip, cf-ipcountry=ZA, x-forwarded-for=41.145.73.111, 162.158.91.116, cf-ray=4067bc9879b997c8-FRA, x-forwarded-proto=http, cf-visitor={"scheme":"https"}, x-parse-application-id=08B182C9F57A24B34AA53E38B0DFD8EC9B74E4ACC72193E62E25628219373301, content-type=application/json, cache-control=no-cache, postman-token=f28c5262-a970-44db-9d22-379e2a44f79d, user-agent=PostmanRuntime/7.1.1, accept=*/*, cookie=__cfduid=d8327f1e50a2c7db19b3091e5f4b147501522793473, cf-connecting-ip=41.145.73.111, x-request-id=594083a0-fd35-4bd0-8ea7-4564a1f00ea1, x-forwarded-port=80, via=1.1 vegur, connect-time=0, x-request-start=1522886450044, total-route-time=0, content-length=257, username=joey2, id=2112694148092739840900, access_token=ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S 2018-04-05T00:00:50.130914+00:00 app[web.1]: error: Google auth is invalid for this user. code=101, message=Google auth is invalid for this user. 2018-04-05T00:00:50.130314+00:00 app[web.1]: error: Error generating response. ParseError { code: 101, message: 'Google auth is invalid for this user.' } code=101, message=Google auth is invalid for this user.

@flovilmart
Copy link
Contributor

I'm not sure why but the id that you have in your logs don't correspond with the subproperty

2112694148092739840900 != 112694148092739840900 is that normal?

@flovilmart
Copy link
Contributor

Also when I try the access token against the validation endpoints, it yeilds an error.

https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S

@josephkandi
Copy link
Author

I had invalidated the token

@josephkandi
Copy link
Author

Try this, token in valid https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=ya29.GluUBUVuN_nJG7Xw9b2IPZxke_9mr2BvX81Up6ALDCLFh0IJPEILHdk_O_vA_RZrcsq1DP1m6kCj9aRdYdCcsIbWg3aIIo_X_rZMGRkCpmzb1DBw-VjqTx0ftq-N

@flovilmart
Copy link
Contributor

flovilmart commented Apr 5, 2018

so the id value that need to be passed is 112694148092739840900.  in your previous transcripts, you can see it starts with a 2 so there's an issue in your code...

@josephkandi
Copy link
Author

Yes, am passing that and still doesnt work

@flovilmart
Copy link
Contributor

can you provide the logs? in the preivous logs that wasn'T what was passed.

@josephkandi
Copy link
Author

josephkandi commented Apr 5, 2018

2018-04-05T00:25:49.553795+00:00 heroku[router]: at=info method=POST path="/parse/users/" host=parse.peruzal.com request_id=0eb14552-c71a-4c81-9dd7-02c3e3317bf3 fwd="41.145.73.111,172.68.186.53" dyno=web.1 connect=0ms service=85ms status=404 bytes=591 protocol=http 2018-04-05T00:25:49.470915+00:00 app[web.1]: verbose: REQUEST for [POST] /parse/users/: { 2018-04-05T00:25:49.470927+00:00 app[web.1]: "username": "joey2", 2018-04-05T00:25:49.470928+00:00 app[web.1]: "authData": { 2018-04-05T00:25:49.470929+00:00 app[web.1]: "google": { 2018-04-05T00:25:49.470931+00:00 app[web.1]: "id": "112694148092739840900", 2018-04-05T00:25:49.471181+00:00 app[web.1]: "access_token": "ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S" 2018-04-05T00:25:49.471185+00:00 app[web.1]: } 2018-04-05T00:25:49.471187+00:00 app[web.1]: } 2018-04-05T00:25:49.471190+00:00 app[web.1]: } method=POST, url=/parse/users/, host=parse.peruzal.com, connection=close, accept-encoding=gzip, cf-ipcountry=ZA, x-forwarded-for=41.145.73.111, 172.68.186.53, cf-ray=4067e13179238076-CPT, x-forwarded-proto=http, cf-visitor={"scheme":"https"}, x-parse-application-id=8D9B2FEA8A92691FF97E70BDCFDDD3F07EFC8199AB23DE0F607A6287D1A844C7, content-type=application/json, cache-control=no-cache, postman-token=a714b6db-6762-463d-b9fe-39e4f0939002, user-agent=PostmanRuntime/7.1.1, accept=*/*, cookie=__cfduid=d8327f1e50a2c7db19b3091e5f4b147501522793473, cf-connecting-ip=41.145.73.111, x-request-id=0eb14552-c71a-4c81-9dd7-02c3e3317bf3, x-forwarded-port=80, via=1.1 vegur, connect-time=0, x-request-start=1522887949466, total-route-time=0, content-length=256, username=joey2, id=112694148092739840900, access_token=ya29.GluTBYW2fX7c26l5u_WKNPpFiz3mRLragUhvjLyhPu4dMtVxIPAyVRtbN8ka4GGfr1H5hQXYFmWagBCPp745HKMPrnYI4okL4QG2WlfN1pAVOKa40w8to7SNri2S 2018-04-05T00:25:49.553019+00:00 app[web.1]: error: Error generating response. ParseError { code: 101, message: 'Google auth is invalid for this user.' } code=101, message=Google auth is invalid for this user. 2018-04-05T00:25:49.553844+00:00 app[web.1]: error: Google auth is invalid for this user. code=101, message=Google auth is invalid for this user.

@flovilmart
Copy link
Contributor

In your logs, your access token is invalid.

@josephkandi
Copy link
Author

Dankie, working, sent an expired token. I think the docs need to be updated to reflect what sort of an id is required. The issue was the id was not the client id from Google Console but rather the subject of the jwt. Shouldn't the code be refactored, am not sure whats the reason behind using the sub field here

function validateIdToken(id, token) { return request("tokeninfo?id_token=" + token) .then((response) => { if (response && (response.sub == id || response.user_id == id)) { return; } throw new Parse.Error( Parse.Error.OBJECT_NOT_FOUND, 'Google auth is invalid for this user.'); }); }

And also think a 404 doesnt reflect the actual error to the client. A clear message like an invalid token or token expired would be helpful

@flovilmart
Copy link
Contributor

Dankie, working, sent an expired token

That's what I thought, this is why I suggested multiple times that you double check what you were sending.

The issue was the id was not the client id from Google Console but rather the subject of the jwt.

I've always mentined the ID as the user ID (which is also the subject of the jwt), you can retrieve the user ID easily following the google documentation: https://developers.google.com/identity/sign-in/ios/people

, am not sure whats the reason behind using the sub field here

The sub field here is what is being sent back by the google endpoints which we validated against to ensure the validity and ownership of the token. All other authentication providers use ta similar strategy. The code doesn't need a refactoring at that point, but if you feel you can make it better, feel free to open a PR.

And also think a 404 doesnt reflect the actual error to the client. A clear message like an invalid token or token expired would be helpful

THe message is actually quite clear, the data you're sending is invalid. Again, if you feel this can be improved, open a PR.

@josephkandi
Copy link
Author

Alright, thanks, will do a PR.

My thinking is there's no need for an extra step to validate the sub field once you get the response from Google.

If you are able to sign in a user in the first place then, that should be good enough without having to do extra validations. If thats a malicious user, that user already can get an access token to retrieve the details they require anywhere.

Also getting the sub field means an extra API call that can be avoided.

@flovilmart
Copy link
Contributor

What guarantees that the data belongs to the right user? Without validating the sub, anyone could impersonate any other user after all... any data coming from a client is untrusted by default. So we will not change this validation nor the logic in this adapter.

@sameersyd
Copy link

Hey I'm having the same issue. It show's Error: Google auth is invalid for this user I have the response, but when I pass googleId and access token, it show's like this.
parse-google-auth-error

And the error looks like this

Screenshot 2020-09-07 at 12 31 35 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants