php check jwt token expired

Solutions on MaxInterview for php check jwt token expired by the best coders in the world

showing results for - "php check jwt token expired"
Emilia
31 Nov 2017
1$jwt = getBearerToken();
2
3try {
4
5$decoded = JWT::decode($jwt, $key, array('HS256'));
6$refresh_token=$decoded->data->refresh_token;
7
8}
9
10catch (Exception $e){
11
12if($e->getMessage() == "Expired token"){
13    list($header, $payload, $signature) = explode(".", $jwt);
14    $payload = json_decode(base64_decode($payload));
15    $refresh_token = $payload->data->refresh_token;
16
17} else {
18
19    // set response code
20    http_response_code(401);
21
22    // show error message
23    echo json_encode(array(
24        "message" => "Access denied.",
25        "error" => $e->getMessage()
26    ));
27    die();
28    }
29}
30