PHP code example of pakpak / jwt-auth

1. Go to this page and download the library: Download pakpak/jwt-auth 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/ */

    

pakpak / jwt-auth example snippets


use PakPak\JwtAuth\JwtAuth;

use PakPak\JwtAuth\JwtAuth;
use PakPak\JwtAuth\JwtPayload;

$payload = new JwtPayload("localhost","user_id");
$key = "My-Secret-Key";

$jwtAuth = JwtAuth::createJwt($payload, $key);

use PakPak\JwtAuth\JwtAuth;

$jwtToken = "header.payload.sign";

$jwtAuth = JwtAuth::byJwt($jwtToken);

// - Validates the token created using the access key
$jwtAuth->verifyJwt("My-Secret-Key");

// - Returns a String containing the JWT Token
$jwtAuth->getJwt();

// - Returns an array containing the Header
$jwtAuth->getHeader();

// - Returns an array containing the Payload
$jwtAuth->getPayload();

use PakPak\JwtAuth\JwtFunctions;

$header = JwtFunctions::createHeader();

use PakPak\JwtAuth\JwtPayload;

//Token’s origin
$issuer = "www.meudominio.com";
//Token’s subject
$subject = "user_id";

$payload = new JwtPayload($issuer,$subject);