Google Api IDtoken,常量?

Google Api IDtoken, Constant?

所以我正在创建一个 wordpress 网站并实施 Google 登录 API,

我设计它是为了让每个用户都有相同的密码(一个长 'gibberish' 字符串)。

//PHP 下面的代码

$usrname =$_REQUEST['/:)REQUEST EMAIL FROM GOOGLE API AFTER SIGN IN:(/']; 

$creds = array();
    $creds['user_login'] = $usrname;
    $creds['user_password'] = 'AIzaSyA9s0cRKrGuhN7oLsjQUxlA1oZroWdWXbc';
    $creds['remember'] = true;

但后来我意识到任何人都可以通过 JS 将电子邮件传递给函数来冒充用户。

编辑:plus 看到了这个。

"Warning: Do not accept plain user IDs, such as those you can get with the GoogleUser.getId() method, on your backend server. A modified client application can send arbitrary user IDs to your server to impersonate users, so you must instead use verifiable ID tokens to securely get the user IDs of signed-in users on the server side."

所以我正在考虑使用从 google api 获得的 CONSTANT 字符串,以便该字符串成为他们的密码。

我需要知道 googleUser.getAuthResponse().id_token;是一个常量变量,所以我可以用它作为密码。

by "Constant" 我的意思是,如果用户在 2010 年验证了我的应用程序并且 ID 令牌是 "XPOXVSCWSW32526C",如果用户需要在 2017 年再次登录,ID 令牌仍然是 "XPOXVSCWSW32526C".

谢谢!

我建议在 this post on the Google developers blog:

中描述的后端架构中使用 ID 令牌
  • 通过 HTTPS 将 ID 令牌字符串(不是常量)发送到您的服务器

  • 使用您服务器上的库(例如,an open source one in PHP from Google)对其进行验证。请务必提供您的 web OAuth 客户端 ID(应该类似于 X.apps.googleusercontent.com)

$curl -sS getcomposer.org/installer | php

$php composer.phar require google/apiclient:dev-master

$php -a

php > require_once 'vendor/autoload.php';

php > $client = new Google_Client(['client_id' => 'web_client_id']);

php > print_r($client->verifyIdToken('id_token_string'));

  • 为您的客户端 ID 成功验证此令牌是您应该用来代替给定用户的密码以进行安全身份验证

  • 使用用户 ID(ID 令牌 'sub' 字段)并将其存储为 字符串 以查找或创建您的用户条目,而不是电子邮件地址,可能会更改

  • 为用户发布会话 cookie 或令牌

有关详细信息,请参阅 developer guide