简体   繁体   English

BulletPHP框架和Firebase / JWT-检查令牌错误

[英]BulletPHP framework and Firebase/JWT - Checking token error

I am developing a REST API with BuletPHP framework. 我正在使用BuletPHP框架开发REST API。 The fact is I have an angular JS app which stores locally the JWT token and sends to the server for checking expiration data. 事实是我有一个有角度的JS应用程序,该应用程序在本地存储JWT令牌并将其发送到服务器以检查到期数据。 I have generated a token and I want to be rejected, but when I check the response It launches this exception: 我已经生成了令牌,并且希望被拒绝,但是当我检查响应时,它将引发此异常:

exception 'Firebase\JWT\BeforeValidException' with message 'Cannot handle token prior to 2015-11-04T18:40:33+0100' in C:\Server\www\vendor\firebase\php-jwt\src\JWT.php:103 Stack trace: #0 C:\Server\www\routes\user.php(92): Firebase\JWT\JWT::decode('eyJ0eXAiOiJKV1Q...', 'QWRhZ2FsIFNpc3R...', Array) #1 [internal function]: Closure->{closure}(Object(Bullet\Request)) #2 C:\Server\www\vendor\vlucas\bulletphp\src\Bullet\App.php(311): call_user_func(Object(Closure), Object(Bullet\Request)) #3 C:\Server\www\vendor\vlucas\bulletphp\src\Bullet\App.php(195): Bullet\App->_runPath('GET', 'eyJ0eXAiOiJKV1Q...') 

Why I am getting this exception on token decoding function? 为什么我在令牌解码功能上遇到此异常?

This is my token: 这是我的记号:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpZCI6IjAyMjAxNTExNjVkMmVhMDM0MjU4ODdhNzE3YzQzNTA4MWNmYzVkYmIxMzMwNjQwIiwibmFtZSI6InJvb3QiLCJpYXQiOjE0NDY0ODYwMzMsIm5iZiI6MTQ0NjY1ODgzM30.qHMee39xJC9Rgx4AUzJSkBUnK3P5R1BTjL_JA5j_6f5L99U-gzZkB4VM0LWrfIMOBFQWFC9lwlUNFPWnwPUiYQ 

This is happening because the time on your local machine/ local server is slightly slower than the remote server(wherever the token is being generated from) time. 发生这种情况是因为本地计算机/本地服务器上的时间比远程服务器(无论从何处生成令牌)的时间稍慢。

If you modify line 113 of vendor\\firebase\\php-jwt\\src\\JWT.php with the following debug you can see the output: 如果使用以下调试修改vendor \\ firebase \\ php-jwt \\ src \\ JWT.php的113行,则可以看到输出:

echo '<br /> payload->iat = '. $payload->iat . '<br />and time() = '.time() . "<br />leeway= ". self::$leeway;

This will output something similar to: 这将输出类似于:

payload->iat = 1447702275  
and time() = 1447702211  
leeway= 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM