I'm encountering an issue verifying a Google ID token using the PHP API. The tokeninfo endpoint successfully verifies it, but $client->verifyIdToken($id_token) returns false in my PHP code. I have also downgraded my PHP version to 7.4
Questions:
- Has anyone else faced this issue with PHP 7.4?
- Are there known compatibility issues with specific library versions?
- Are there additional troubleshooting steps I can try?
Any guidance would be greatly appreciated.
Here's an the code I am using:
<?php
require_once 'vendor/autoload.php';
// Get $id_token via HTTPS POST.
$CLIENT_ID = 'token-xxx-xxx-xxx-xx-000.apps.googleusercontent.com';
$id_token = $_POST['credential'];
$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token); //Not working
echo file_get_contents('https://oauth2.googleapis.com/tokeninfo?id_token='.$id_token); //Works
echo var_dump($payload); //false
if ($payload) {
//$userid = $payload['sub'];
// If request specified a G Suite domain:
//$domain = $payload['hd'];
} else {
// Invalid ID token
}
?>
Steps taken:
- Verified client ID is correct.
- Checked for error messages or exceptions.
- Inspected the $payload variable after verification.
- Verified network traffic to Google's servers.