我正在token-id
从 android 客户端接收。
在第一步中,我通过以下代码验证令牌:
$tokenId = $request->get('token-id');
$google_client = new Google_Client();
$google_client->setApplicationName("Ashojash");
$google_client->setClientId(env("GOOGLE_KEY"));
$google_client->setClientSecret(env("GOOGLE_SECRET"));
$google_client->setIncludeGrantedScopes(true);
$google_client->addScope(['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/plus.login']);
$credentials = $google_client->verifyIdToken($tokenId);
if ($credentials)
{
$data = $credentials->getAttributes();
// validate aud against server client_id
return $data['payload']['sub']; // user ID
}
return false;
从谷歌收到的数据是:
array:2 [
"envelope" => array:2 [
"alg" => "RS256"
"kid" => "23e5872762976b37944c33e4b2602656093ece91"
]
"payload" => array:12 [
"iss" => "https://accounts.google.com"
"aud" => "346904023124-73h70s03c0dipla8ltcbcd2ko076ft43.apps.googleusercontent.com"
"sub" => "111167217866315036918"
"email_verified" => true
"azp" => "346904023124-lehbs8510nibuq5ci125h8mu6u2ir4q1.apps.googleusercontent.com"
"email" => "jhon.f.kenedy777@gmail.com"
"iat" => 1452178925
"exp" => 1452182525
"name" => "john F.kenedy"
"given_name" => "john"
"family_name" => "F.kenedy"
"locale" => "en"]
]
验证令牌 ID 后,如何获取用户信息?
我感兴趣的是:
1-电子邮件
2-用户基本信息
3-Google 加信息
我也安装了 Socialite,所以如果可能的话,也包括你对 Socialite 的回答。