kreait / firebase-tokens-php

A PHP library to work with Firebase tokens
MIT License
223 stars 33 forks source link

Missing key when declaring a validator #4

Closed GershonHerczeg closed 7 years ago

GershonHerczeg commented 7 years ago

{ "message": "Unknown key", "error": "A key with ID \"The token with ID \"%s\" is unknown.\" could not be found." }

I get that error after declaring $verifier = new Verifier($projectId);

Looks like it expects to get the key from some header value or a declared value when the object in created. public function __construct(string $projectId, KeyStore $keys = null, Signer $signer = null)

Would you happen to have a better working code example?

jeromegamez commented 7 years ago

Hey Gershon,

the library is so small, there is not much room for a better code example :). It's just an implementation of the steps described at https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_a_third-party_jwt_library

However, when just creating a new instance of the Verifier should not provoke the error you are describing, as nothing happens on instantiation - only when actually trying to verifiy an ID token.

The project ID should be a value that you can find in the Service Account JSON file for your Firebase project. The ID token to verify should come from outside, for example from a Firebase Web application, as described here: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients

That's why I unfortunately have no idea where the error you described is coming from. Could you show me a working full code example so that I van replicate the issue, please?

GershonHerczeg commented 7 years ago

@jeromegamez yes error occurs after the try catch $verifiedIdToken = $verifier->verifyIdToken($idTokenString); i am going to research the kid issue further.

stanislavhannes commented 5 years ago

If someone has the same issue: the reason for this exception might be the used idToken. Because there is an idToken in the user object after a successfull login, but with this it won't work and u will get the exception as described. To get a valid ID Token u have to use the functions as described here: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients