Skip to content

Fatal error: Uncaught exception 'Firebase\JWT\ExpiredException' with message 'Expired token'  #168

@hamburger123456

Description

@hamburger123456

Hello,
I get this message: Fatal error: Uncaught exception 'Firebase\JWT\ExpiredException' with message 'Expired token' in /www/lalalal/jwtTest/JWT/JWT.php:134 Stack trace: #0 /www/lallal/jwtTest/index.php(63): Firebase\JWT\JWT::decode('eyJ0eXAiOiJKV1Q...', 'example_key', Array) #1 {main} thrown in /www/lalalla/jwtTest/JWT/JWT.php on line 134
Do I have to declare my own Exception? I'am using this code to provide an expired exp-date:

<?php
use \Firebase\JWT\JWT;
require 'JWT/JWT.php';
require 'JWT/BeforeValidException.php';
require 'JWT/ExpiredException.php';
require 'JWT/SignatureInvalidException.php';

$key = "example_key";
$token = array(
    "iss" => "http://example.org/",
    "aud" => "http://example.com/",
    "iat" => 1356999524,
    "nbf" => 1357000000,
    "exp" => time()-1000
);
$jwt = JWT::encode($token, $key);    //HS256 by default.
echo "jwt: ".$jwt;
echo $t."--------------------------".$t;
$decoded = JWT::decode($jwt, $key, array('HS256'));

My source-files are still downloaded (newest) and untouched. PHP Version ist 5.6.29

OK. I think I get it: To get use to it you have to wrap in try:

try {
   $decoded = JWT::decode($jwt, $key, array('HS256'));
} catch (Exception $e) {
    echo 'Exception catched: ',  $e->getMessage(), "\n";  
}

May be you shout add this to your example.
I'am beginner so are there other possibilities? And why are you defining your own Exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions