// Include the required Google PHP client library require_once 'google-api-php-client/vendor/autoload.php'; // Initialize the Google_Client object $client = new Google_Client(); // Set the client ID and secret $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); // Get the token ID from the request $id_token = $_REQUEST['id_token']; // Verify the token ID $payload = $client->verifyIdToken($id_token); if ($payload) { $subject = $payload['sub']; // User is authenticated, perform action } else { // Token verification failed }
// Use the Google_Client method without retrieving the user ID $client = new Google_Client(); $id_token = $_REQUEST['id_token']; $payload = $client->verifyIdToken($id_token); if ($payload) { // User is authenticated, perform action } else { // Token verification failed }The Google_Client verifyIdToken method is part of the Google API PHP client library, which can be downloaded and included in a project using Composer or by manually installing the package.