kreait / firebase-tokens-php

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

Error:Generator class is reserved for internal use. #3

Closed esafwan closed 7 years ago

esafwan commented 7 years ago

When trying out your code, as per the example in the readme. I am getting an error as below:

[Sun Jun 11 02:14:08.042454 2017] [:error] [pid 1813] [client 192.168.0.118:63309] PHP Fatal error: Uncaught Error: The "Generator" class is reserved for internal use and cannot be manually instantiated in /var/www/html/firebase/generate_token.php:10\nStack trace:\n#0 {main}\n thrown in /var/www/html/firebase/generate_token.php on line 10, referer: http://192.168.0.105/firebase/

My sample code is given below:

<?php 
use Firebase\Auth\Token\Handler;

$projectId = 'test'; //replaced
$clientEmail = 'test@test.com'; //replaced

$generator = new Generator($clientEmail, $privateKey);

$uid = '1';
$claims = ['email' => 'some1@gmail.com',
           'username' => 'some1'

          ];

$token = $generator->createCustomToken($uid, $claims); 
// Returns a Lcobucci\JWT\Token instance

echo $token; // "eyJ0eXAiOiJKV1..."
?>
jeromegamez commented 7 years ago

Hi @esafwan, thank you for reaching out!

The following statement is missing in the code snippet above:

use Firebase\Auth\Token\Generator;

Without it, PHP tries to use the Generator class from the root namespace, which indeed cannot be instantiated.