Google_Client::verifyIdToken return invalid token signature
I'm trying to work with the php client of google Oauth2 api to validate an id_token. The id_token is provided by a javascript app on which the user login his google account, and i'm givin this token to my php api server, in order to validate it and retrieve the right informations from my bdd.
The login in javascript is successfull and the access and id_token seems right, but when I try to verify it with Google_Client->verifyIdToken()
$client = new Google_Client(); $ticket = $client->verifyIdToken(myToken); , it return an invalid token signature exception (fail when trying to use the google cert to valid the token).
My first assumption was to think the token is not valid, so to make sur it is, i submited it to google validation url https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=token
it return user info, so my token seems to be valid :
{ issuer: "accounts.google.com", issued_to: "id", audience: "id", user_id: "id", expires_in: 2149, issued_at: 1397636222, email: "mail", verified_email: true } Tried everything i can think of, but can't solve this one. can someone help me ?
Question asked on stackoverflow too : http://stackoverflow.com/questions/23104721/google-oauth2-verifyidtoken-return-invalid-token-signature-with-valid-id-token
Odd. Can you step through the validate function to see which part it is failing on?
it fail inside OAuth2:verifySignedJwtWithCerts. Line 500 of OAuth 2.php
// Check signature $verified = false; foreach ($certs as $keyName => $pem) { $public_key = new Google_Verifier_Pem($pem); if ($public_key->verify($signed, $signature)) { $verified = true; break; } }
Could you see where in the verify function it is hitting an issue? There are multiple checks in there, and might clarify things to see what it is failing on.
Seems to happen when Pem::verify call openssl_verify, it always return 0 (not -1, never get the exception thrown)
Can you check the date and time on the machine is right? I'm wondering if there is a bad cached cert or similar.
seems to be good, is there a way to flush this cache ?
Just delete it - it should be in your system temp file directory.
deleted the google_client folder from temp directory, error still here
Hmm, just to check you are using an up to date id token for your testing? The Google certificates are rotated every few hours, so an old id token wont be valid any more.
i just did a new authentification. The token look like the same than last week for me. But https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=token return valid informations
Hmm, the token really should not look (exactly) the same week to week - there is a timestamp in there for one. How are you retrieving the id token?
retrieving it from the callback function of my signin button in javascript. It's a property of my access token
Only thing I can guess is that its an incompatibility with the versions of openssl on the machine. Do you know which version of libopenssl or similar you have?
seems to have a really old version : OpenSSL 0.9.8q 2 Dec 2010
I am guessing that is the issue. Not totally sure what might be incompatible, but I think moving to a newer openssl should solve it.
It's timezone fault! in my case it's work(day), not work(night after 12AM), work again(tomorrow)! when it's stop working, just set timezone to America/New_York and its work, remove timezone then stop working. And its happened because of some country have future date window rather than usA. you know that if you change your system date time then SSL stop working. I think it's the same problem. google sign it for it's own today but actually your yesterday!
php 7.1 macOS Sierra Timezone 3:30
@NexProME Are you sure ? i just used both date_default_timezone_set('America/Los_Angeles'); and date_default_timezone_set('America/New_York'); and it's still not working. However, i can confirm that it does work during the day and stops working as darkness conquers the sky.
@ianbarber Moving to OpenSSL/1.0.2l (this is the version of OpenSSL that is printed out by phpinfo()) didn't fix the issue. What should i do now ?