【发布时间】:2018-12-30 16:11:21
【问题描述】:
我正在尝试使用这个库生成 PHP 令牌, https://github.com/lcobucci/jwt/blob/3.2/README.md ,我执行了这段代码:
$signer = new Sha256();
$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
->setAudience('http://example.org') // Configures the audience (aud claim)
->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
->setExpiration(time() + 3600) // Configures the expiration time of the token (exp claim)
->set('uid', 1) // Configures a new claim, called "uid"
->sign($signer, 'testing') // creates a signature using "testing" as key
->getToken(); // Retrieves the generated token
如何检查请求是否带有此标志:->sign($signer, 'testing')
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
这个函数检查符号是否正确,但是,我需要检查带有来自请求的符号的令牌。
【问题讨论】:
标签: php json codeigniter jwt