React-google-login: Object keys has changed

Created on 31 Aug 2016  路  27Comments  路  Source: anthonyjgrove/react-google-login

Hello,

This day I tried to connect through Google with this package, and return object's key has changed.

| Old Key | New Key | Detail |
| :-: | :-: | :-: |
| el | El | Google ID |
| hg | Zi | Token Details |
| wc | w3 | Profile Detail |

Did you guys have this issue ?

Most helpful comment

I use response.getAuthResponse().id_token to get id_token
this work with both old and new object key
Should we use this function instead of response.hg.id_token which is used in readme?

I'm not sure if response.getBasicProfile() will work too.

All 27 comments

Yes, I got the same issue. I believe the keys will change every time the library is compiled. Better have something to wrap this up.

Same Issue... Is there a way to permanently fix this ?

Just to be sure, this change is coming from Google ? Because what I've seen from this package is a function returning the response directly ..

If this is the case, we need to handle mapping (and give a sense to those ugly keys)

Yes, It looks like Google changed their response, it is probably best we figure out a good way to permanently map the Google keys to our own key names along with using better naming convention for those keys.

I am going to map it to the old keys for a quick fix so people don't need to update their code, then change the key names for the next version.

Pushed a quick fix, Let me know if you guys have any feedback on renaming the keys for version 3.0

Great @anthonyjgrove, thanks for the hotfix !

But I think it's even more than that, they also changed the child keys. I still ignore why they did such a thing, even more for completely sense-less keys.

hmm if they changed the child keys that might be a bigger issue unless someone has the old ones somewhere?

Also here is what I am looking at for updated key names:

| property name | value | definition |
| :-: | :-: | :-: |
| googleId | string | Google user ID |
| tokenObj | object | Token details object |
| profileObj | object | Profile details object |

+1 for the 3.0.0 change

Sounds nice ! But is this deserve a major release ?

For old keys, I know profile picture was wc.Ph now it's w3.Qaa (???) and email was wc.hg and now it's w3.U3 (???)

This might be kinda hardcore to map those data properly if even child keys are changing .. On what we gonna base mapping, positioning ?

If someone has news or blogpost to give about those changes, please provide them !

I guess it doesn't need to be a major release but it is a big change to those who have it implemented.

I think to properly patch this bug It would be good to map the child keys to their old values as well, then for the minor/ major version update rename the child keys to better names as well.

Problem is, we don't have old child key yet.

Also does anyone know if the child keys change based on the scope?

I use response.getAuthResponse().id_token to get id_token
this work with both old and new object key
Should we use this function instead of response.hg.id_token which is used in readme?

I'm not sure if response.getBasicProfile() will work too.

That's smart, I think one time I've saw functions to access data, maybe that's the way we should those login data, and passing through the object keys is doing hardcoding ...

@serm-mb Thanks for bringing that up. From what I can tell it is probably Google's intentions for developers to use the object's methods to access the returned information rather pulling it directly off the returned objects key., Then it would make sense for the keys to not have a straightforward naming structure and for them to randomly change them one day.

Moving foward should I update the docs to support only using the return object methods or should I also offer an updated naming structure as well if people just want to access it off the returned object like is currently outlined in the docs?

I think people will prefer having an object with all the data in it and meaningful keys (for those who wants to put directly the object in their store)

You can also include the response then @serm-mb 's people can still query with functions.

Of course, this deserve a minor release.


History has changed again : Now profile picture key is changing from w3.Qaa to w3.Paathus breaking my app. Still don't know why they are doing such things.

I've just tried this, and it works well for me :)

response.getAuthResponse().access_token
response.getBasicProfile().getEmail()

Pushed 2.4.0, Let me know if i am missing anything.

@anthonyjgrove Now the wc has changed to xc

Is this due to a change in Google's response?

Screen Shot 2020-11-18 at 5 17 03 pm

You should be using tokenObj not xc. the xc key seems to change now and then.

You should be using tokenObj not xc. the xc key seems to change now and then.

Thanks @anthonyjgrove for the response.

My use case required the access_token which isn't consistently available in the top-level and not available in tokenObj but has been available under the wc or now xc keys. I have updated to now get access_token via response.getAuthResponse(true) which seems to work great and thus removed dependency on these key names.

But as part of root cause analysis, I wanted to understand what is the source of these inconsistent wc or xc keys. Is it part of Google's response?

You should be using tokenObj not xc. the xc key seems to change now and then.

Thanks @anthonyjgrove for the response.

My use case required the access_token which isn't consistently available in the top-level and not available in tokenObj but has been available under the wc or now xc keys. I have updated to now get access_token via response.getAuthResponse(true) which seems to work great and thus removed dependency on these key names.

But as part of root cause analysis, I wanted to understand what is the source of these inconsistent wc or xc keys. Is it part of Google's response?

Can you make an PR with that logic? The component should probably be using that getter to set the accessToken inside the hook instead of grabbing it from the returned object. https://github.com/anthonyjgrove/react-google-login/blob/master/src/use-google-login.js#L37

wc and xc are returned by google but I do not think they expect you to access them directly but use the getters like you are doing now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emwee picture emwee  路  4Comments

SSR
rlancer picture rlancer  路  8Comments

Ethan0007 picture Ethan0007  路  3Comments

eap picture eap  路  7Comments

scolyer picture scolyer  路  3Comments