Then, send the ID token to your server with an HTTPS POST request:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://yourbackend.example.com/g_PHP_SDK/vendor/google/apiclient/src/Google/Client.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText);
};
xhr.send('idtoken=' + id_token);
Alternatively, you can set the same ini directive dynamically in your code.
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');
Or I must have sthg like: // in target of this file xhr.open('POST', 'https://yourbackend.example.com/g_PHP_SDK/yyy.php');
if yes, what lib PHP of google import and how? and where (in what lib file - installed via Composer) add my keys?
getUserFromToken($_POST["idtoken"]);
function getUserFromToken($token) { // https://developers.google.com/api-client-library/php/guide/aaa_idtoken
$ticket = $client->verifyIdToken($token);
if ($ticket) {
$data = $ticket->getAttributes();
return $data['payload']['sub']; // user ID
}
return false
}
getUserFromToken($_POST["idtoken"]); // after many tries this must be the problem - I use SDK JS and want verify key on the server(PHP) but getting nothing from this(last post) function run - may called wrong... how call this?
I think problem was using: return , rather: echo , in ajax/PHP... that is Nothing returned...