dongtou2016 2019-01-22 12:04
浏览 30
已采纳

如何通过PHP安全地检索谷歌用户ID?

I'm trying to set up a system that a user could sign up through google sign-in and I need a detail about a user that will always be constant. I figured that would be the ID, but that's pretty much the only detail I can't get through PHP.

I can get the details about a user using a token ID and it would return this.

"iss": "https://accounts.google.com",
 "sub": "110169484474386276334",
 "azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
 "aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
 "iat": "1433978353",
 "exp": "1433981953",

 // These seven fields are only included when the user has granted the "profile" and
 // "email" OAuth scopes to the application.
 "email": "testuser@gmail.com",
 "email_verified": "true",
 "name" : "Test User",
 "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
 "given_name": "Test",
 "family_name": "User",
 "locale": "en"

But I can't find a detail that would be unique and constant so I can see if their account already exists. Is there something else I could use or can I retrieve the ID of a user through php?

  • 写回答

1条回答 默认 最新

  • douxie7339 2019-01-22 12:39
    关注

    I'm not sure about the labels above or where you got them, but looking at the values (and comparing them to my own collection of Gmail User IDs from Oauth), the sub value is the user ID field.

    Counterintuitively, email is not unique, as in one account can have several email aliases, and you can change email addresses on an account.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳