You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useLcobucci\JWT\Configuration;
$config = newConfiguration();
$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 tokenvar_dump($token->verify($signer, 'testing 1')); // false, because the key is differentvar_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?
The text was updated successfully, but these errors were encountered:
@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.
Using the code from example:
I get the following error:
Is there anything I'm doing wrong?
The text was updated successfully, but these errors were encountered: