Trying to this google client API example
https://developers.google.com/identity/sign-in/web/backend-auth
I get my access token via javascript and post it to my PHP via ajax javascript object is below.
expires_at
:
1490552860336
expires_in
:
2223
first_issued_at
:
1490549260336
id_token
:
"eyJhbGciOiJSUzI1NiIsImtpZCI6ImRkMDM4NzVmMzkzMTdiZThlNTc0MDBlNmMzMDYzMmFmNTU4YzJkZTQifQ.eyJhenAiOiI5Mjg3MzEzODM5NzQtc3RsdmFyc291cnZoNmdqaDdvbjkwZWwxOGhjOHVrNXYuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI5Mjg3MzEzODM5NzQtc3RsdmFyc291cnZoNmdqaDdvbjkwZWwxOGhjOHVrNXYuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTQ1MTMzNjU2ODMwMzExNzMwOTgiLCJlbWFpbCI6IndoeXRlYXZlbWVjaGFuaWNhbEBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXRfaGFzaCI6IkF2SUZQaHNjVmFNY1htTEdtand6M2ciLCJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiaWF0IjoxNDkwNTQ5MjU2LCJleHAiOjE0OTA1NTI4NTYsIm5hbWUiOiJUcmF2aXMgS2xlaW4iLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDQuZ29vZ2xldXNlcmNvbnRlbnQuY29tLy1BdzlCUjF4YnVBNC9BQUFBQUFBQUFBSS9BQUFBQUFBQUFBQS9BTWNBWWk5b2ZNV1NtcllGc2pTc0xUcFpZZHhkT0FEaGZBL3M5Ni1jL3Bob3RvLmpwZyIsImdpdmVuX25hbWUiOiJUcmF2aXMiLCJmYW1pbHlfbmFtZSI6IktsZWluIiwibG9jYWxlIjoiZW4ifQ.PBcvfMs9_MO9mcHDtGGyb3VbO-O374tHH7w4gWr8ZMpRDYyynY6ZQd5BxRxlh6b__upzxz6gMYQ29yY__zDnEp4_NrkSp7RWQAcoF-JuY8xM1GtDy5IwEFKPxDh9h-9bGoxCx5jgX7-bu2F5Xk6opwZUzoyyYk5BT1xXpBfAe35CJHK_NAzSfrwEX8vU-hIP9C_BjipXptg5Eo3fi3DxPWRVbrzsscV0DDASm9xEi5ilLkUxBwRZN9bk6hgXXgn2Ts7Mo4B7Rue1oyB_rkNJ3RSgH7ylnHrVePiVwJ_15aKwiD64FgcmdLOruLEm9pADoiAodMVNZ6HAElr3MuWG1w"
idpId
:
"google"
login_hint
:
"AJDLj6JimYVJadfBfXai38izEPbdRaSSCtY5FyzYIVQ1IPE2kad13fq5-9Qwkik2AlWx3_Qlco531-R7LVEwcxvs8Xhw0TvrSg"
session_state
:
Object
token_type
:
"Bearer"
my PHP is as follows
require_once 'google-api-php-client-2.1.1/vendor/autoload.php';
// Get $id_token via HTTPS POST.
$client = new Google_Client(['client_id' =>'my google client id' ]);
$payload = $client->verifyIdToken($this->input->post('id_token'));
if ($payload) {
$userid = $payload['sub'];
// If request specified a G Suite domain:
//$domain = $payload['hd'];
} else {
// Invalid ID token
}
So frustrating I've never had luck with google API examples. I can't seem to find anything on the net to get this to work its been days. Please help me. I'm basically looking for an id or token I can verify and save in my database
I'm getting stuck on this function
$payload = $client->verifyIdToken($this->input->post('id_token'));
Screen shot shows how far I get before an error is thrown.
I ended up going this route
$q = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' . $this->input->post('id_token');
$json = file_get_contents($q);
$userInfoArray = json_decode($json,true);
$googleEmail = $userInfoArray['email'];
$google_id= $userInfoArray['kid'];
I'm not sure if the kid is a unique id for the user or not but it keeps returning the same value.