parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Google authDataManager is not validating access_tokens correctly

Open cipiripper opened this issue 10 years ago • 12 comments

Issue Description

Google authDataManager is not validating access_tokens correctly. It validates them on correct endpoint, but with wrong url param, id_token instead of access_token. See this in code here.

So you are never able to validate a token, even if it is a valid one.

How it should be done

Here is the link on google docs that says that token to be validated should be passed on access_token URL parameter.

I'll create a pull request for this issue.

cipiripper avatar Jul 15 '16 15:07 cipiripper

It seems that we'd need both, with id_token and access_token. Can you take that into account?

flovilmart avatar Jul 15 '16 15:07 flovilmart

Sure. But are you sure about id_token being used? Is that used for some different kind of tokens?

cipiripper avatar Jul 15 '16 15:07 cipiripper

Yes I'm pretty sure about that: https://github.com/ParsePlatform/parse-server/pull/2023 (see the docs and notes)

flovilmart avatar Jul 15 '16 15:07 flovilmart

I see, "id_tokens" is used for Android clients... Okay.

cipiripper avatar Jul 15 '16 15:07 cipiripper

Yeah, that's painful this doc... Now I'm worried that people send their 'id_token' as 'access_token' and that it may lead to a breaking change...

flovilmart avatar Jul 15 '16 15:07 flovilmart

@flovilmart One relatively off topic question (so I do not post new issue). Shouldn't user._linkWith() generate a sessionToken when passed a valid authData? I mean, work the same as user.login().

I'm calling this in cloud code, and I am trying to allow users to login using username:password or their google account...

cipiripper avatar Jul 18 '16 10:07 cipiripper

If you are already logged in, you should have a session token already, and we regenerate the tokens only when re-setting the passwords.

flovilmart avatar Jul 18 '16 12:07 flovilmart

This line: return request("tokeninfo?id_token="+authData.access_token)causes "code: 101, message: Google auth is invalid for this user." error.

Trying this https://www.googleapis.com/oauth2/v3/tokeninfo?id_token="123XYZ" on a browser gives "error_description": "Invalid Value"

This should be changed to return request("tokeninfo?access_token="+authData.access_token) which gives the right response from the Google Authorization Server.

hslorenzo avatar Oct 17 '16 15:10 hslorenzo

Both are valid, depending where your token is coming from https://github.com/ParsePlatform/parse-server/commit/6415a35433d8a7e1bd5bf55a58defbc1a80fc0a6

flovilmart avatar Oct 17 '16 15:10 flovilmart

@hslorenzo @cipiripper I've submitted a PR, if you wanna use id_token validation, you can use the id_token property instead of the access_token. If access_token validation fails, it will try the id_token validation for backwards compatibility.

flovilmart avatar Oct 17 '16 15:10 flovilmart

Man, this google API is maddening...

flovilmart avatar Oct 24 '16 20:10 flovilmart

See: https://developers.google.com/identity/protocols/OAuth2UserAgent#tokeninfo-validation

AND:

https://developers.google.com/identity/sign-in/web/backend-auth#calling-the-tokeninfo-endpoint

flovilmart avatar Oct 24 '16 20:10 flovilmart