kreait / firebase-tokens-php

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

How to clear cache? #29

Closed produktive closed 4 years ago

produktive commented 4 years ago

Cache results from the Google Secure Token Store

In order to verify ID tokens, the verifier makes a call to fetch Firebase's currently available public keys. The keys are cached in memory by default.

How do I clear this cache? I created a new project and it is still looking for the old project name.

jeromegamez commented 4 years ago

The InMemory Cache is cleared after a script/request is terminated. If you're using another kind of cache provided by another library, you need to look up in their docs how to clear the cache.

I'm not sure what you mean, though: only the public keys from Google are cached, and these are not tied to a Firebase project or a project's name 🤔

produktive commented 4 years ago

Hmm, then I'm not sure what type of problem I'm experiencing. I had this working a few days ago. I deleted my old Firebase project (ccamd-fish-tracker) and created a new one (cca-md). Since then, I'm getting this error: PHP message: attempt to error The value 'eyJhbGciOiJSUzI...' is not a verified ID token:

This is my verify function:

function verify($tokenid) {
    if (isset($tokenid)) {

        $projectId = 'cca-md'; // cca-md
        $idToken = $tokenid; // An ID token given to your backend by a Client application

        $verifier = IdTokenVerifier::createWithProjectId($projectId);

        try {
            $token = $verifier->verifyIdToken($idToken);
        } catch (IdTokenVerificationFailed $e) {
            $data = $e->getMessage();
            $token = null;
        }

        try {
            $token = $verifier->verifyIdTokenWithLeeway($idToken, $leewayInSeconds = 300);
        } catch (IdTokenVerificationFailed $e) {
            $data = $e->getMessage();
            $token = null;
        }
    } else {
        $token = null;
    }
    return $token;
}

I'm not sure where it's still getting my old project name from?

produktive commented 4 years ago

Wow I'm an idiot. I found the problem, it was using the wrong project name is a different file. Sorry for the bother.

jeromegamez commented 4 years ago

No problem, I was just about to suggest the same, and you saved me from writing it 😅. Glad you came to the solution yourself, it's always more satisfying this way 💪