Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding secret #148

Closed
RenatoPta opened this issue Dec 8, 2016 · 3 comments
Closed

Error when adding secret #148

RenatoPta opened this issue Dec 8, 2016 · 3 comments

Comments

@RenatoPta
Copy link

RenatoPta commented Dec 8, 2016

Using the code from example:

use Lcobucci\JWT\Configuration;

$config = new Configuration();
$signer = $config->getSigner(); // Default signer is HMAC SHA256

$token = $config->createBuilder()
                ->issuedBy('http://example.com') // Configures the issuer (iss claim)
                ->canOnlyBeUsedBy('http://example.org') // Configures the audience (aud claim)
                ->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
                ->issuedAt(time()) // Configures the time that the token was issue (iat claim)
                ->canOnlyBeUsedAfter(time() + 60) // Configures the time that the token can be used (nbf claim)
                ->expiresAt(time() + 3600) // Configures the expiration time of the token (exp claim)
                ->with('uid', 1) // Configures a new claim, called "uid"
                ->sign($signer, 'testing') // creates a signature using "testing" as key
                ->getToken(); // Retrieves the generated token


var_dump($token->verify($signer, 'testing 1')); // false, because the key is different
var_dump($token->verify($signer, 'testing')); // true, because the key is the same

I get the following error:

Fatal error: Uncaught TypeError: Argument 2 passed to Lcobucci\JWT\Builder::sign() must be an instance of Lcobucci\JWT\Signer\Key, string given, called in D:\Projetos\JWT-PHP\teste.php on line 18 and defined in D:\Projetos\JWT-PHP\Lcobucci\JWT\Builder.php:245 
Stack trace: 
#0 D:\Projetos\JWT-PHP\teste.php(18): Lcobucci\JWT\Builder->sign(Object(Lcobucci\JWT\Signer\Hmac\Sha256), 'testing') 
#1 {main} thrown in D:\Projetos\JWT-PHP\Lcobucci\JWT\Builder.php on line 245

Is there anything I'm doing wrong?

@RenatoPta
Copy link
Author

I changed the type Key to String in second paramter "$key" in file Lcobucci\JWT\Builder.php:245 and it worked

@lcobucci
Copy link
Owner

lcobucci commented Dec 9, 2016

@RenatoPta the problem is that the documentation is outdated and you're using an unstable version.
A lot of things will change (as you can see on #129), including the documentation.

If you are fine with that and don't mind changing your code until v4 is released you should not change the library's code and just pass an instance of Key instead of a string.

Although I appreciate people trying things out with the development version I'd recommend you to use v3.2.

@lcobucci
Copy link
Owner

lcobucci commented Dec 9, 2016

Closing as won't fix since the documentation is going to be updated on the validation refactoring PR

@lcobucci lcobucci closed this as completed Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants