PHP code example of codeblog / jwt

1. Go to this page and download the library: Download codeblog/jwt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codeblog / jwt example snippets




odeBlog\JWT\JWT;

$key = 'codeblog.com.br'; // your secret key

$payload = array(
    "iss" => "api.dominio.com", // the token emitter. You can use the domain where your api is. Ex: api.domain.com
    "iat" => time(), // The time the JWT was issued. Can be used to determine the age of JWT.
    "exp" => time() + (60 * 60), // This is likely to be the most commonly used registered claim. This will set the expiration on the NumericDate value. The expiration MUST be after the current date / time.
    "data" => [
        "user_id" => 10,
        "user_email" => "[email protected]"
    ]
);


$jwt = (new JWT)->encode($payload, $key);
var_dump($jwt);

//$decoded = JWT::decode($jwt, $key);
//var_dump($decoded);



odeBlog\JWT\JWT;

$key = 'codeblog.com.br'; // your secret key

$jwt = new JWT();
$token = $jwt->authHeader();

$decoded = $jwt->decode($token, $key);
var_dump($decoded);