1. Go to this page and download the library: Download kreait/firebase-tokens library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Kreait\Firebase\JWT\Error\IdTokenVerificationFailed;
use Kreait\Firebase\JWT\IdTokenVerifier;
$projectId = '...';
$idToken = 'eyJhb...'; // An ID token given to your backend by a Client application
$verifier = IdTokenVerifier::createWithProjectId($projectId);
try {
$token = $verifier->verifyIdToken($idToken);
} catch (IdTokenVerificationFailed $e) {
echo $e->getMessage();
// Example Output:
// The value 'eyJhb...' is not a verified ID token:
// - The token is expired.
exit;
}
try {
$token = $verifier->verifyIdTokenWithLeeway($idToken, $leewayInSeconds = 10000000);
} catch (IdTokenVerificationFailed $e) {
print $e->getMessage();
exit;
}
use Kreait\Firebase\JWT\Error\SessionCookieVerificationFailed;
use Kreait\Firebase\JWT\SessionCookieVerifier;
$projectId = '...';
$sessionCookie = 'eyJhb...'; // A session cookie given to your backend by a Client application
$verifier = SessionCookieVerifier::createWithProjectId($projectId);
try {
$token = $verifier->verifySessionCookie($sessionCookie);
} catch (SessionCookieVerificationFailed $e) {
echo $e->getMessage();
// Example Output:
// The value 'eyJhb...' is not a verified ID token:
// - The token is expired.
exit;
}
try {
$token = $verifier->verifySessionCookieWithLeeway($sessionCookie, $leewayInSeconds = 10000000);
} catch (SessionCookieVerificationFailed $e) {
print $e->getMessage();
exit;
}
use Kreait\Firebase\JWT\CustomTokenGenerator;
$generator = CustomTokenGenerator::withClientEmailAndPrivateKey('...', '...');
$tenantAwareGenerator = $generator->withTenantId('my-tenant-id');
use Kreait\Firebase\JWT\IdTokenVerifier;
$verifier = IdTokenVerifier::createWithProjectId('my-project-id');
$tenantAwareVerifier = $verifier->withExpectedTenantId('my-tenant-id');
use Kreait\Firebase\JWT\IdTokenVerifier;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
$cache = new FilesystemAdapter();
$verifier = IdTokenVerifier::createWithProjectIdAndCache($projectId, $cache);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.