vendredi 17 juin 2022

Laravel 5.4 PHP 7.4 sometime getting JWT token decoding issue with different different exceptions and sometime its working properly

Function to generate token

function authTokenGenerator($name, $id): string
{
    $payload = [
        'iat' => time(),
        'exp' => time() + 3600,
        'nam' => $name,
        'sid' => $id,
    ];
    try {
        $token = JWT::encode($payload, env('SECRET'), 'HS256');
    } catch (Exception $exception) {
        throw $exception;
    }
    $decodeToken = JWT::decode($token, env('SECRET'), ['HS256']);
    if (!isset($decodeToken) || empty($decodeToken)) {
        $this->generateJwtToken($panNumber, $sessionId);            
    }
    return $token;
}

**Inside middle ware we are using **

$decoded = JWT::decode($request->header('token') , $key, ['HS256']);

to decode token and here we get sometimes issues.

[2022-06-16 17:58:38] local.ERROR: Signature verification failed {"exception":"[object] (Firebase\JWT\SignatureInvalidException(code: 0): Signature verification failed at vendor/firebase/php-jwt/src/JWT.php:122)

[2022-06-16 17:58:44] local.ERROR: Signature verification failed {"exception":"[object] (Firebase\JWT\SignatureInvalidException(code: 0): Signature verification failed at vendor/firebase/php-jwt/src/JWT.php:122)

[2022-06-17 16:41:37] local.ERROR: {"Issue Token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NTU0NjQzMjUsImV4cCI6MTY1NTQ5MzEyNSwicGFuIjoiR01QUFMxMjQzTCIsInNpZCI6MzQ5MDgyOTR9.IKxOY46C_J4r_JKOkVuWQdFeFLjhIWdTGE8bI0-2kxg","Session":"34908294","Exception_Message":"Cannot handle token prior to 2022-06-17T16:42:05+0530","file":"vendor/firebase/php-jwt/src/JWT.php","Line":137}

[2022-06-17 16:41:37] local.ERROR: Cannot handle token prior to 2022-06-17T16:42:05+0530 {"exception":"[object] (Firebase\JWT\BeforeValidException(code: 0): Cannot handle token prior to 2022-06-17T16:42:05+0530 at vendor/firebase/php-jwt/src/JWT.php:137)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/J5xhjif
via IFTTT

Aucun commentaire:

Enregistrer un commentaire