PHP code example of byjg / jwt-wrapper
1. Go to this page and download the library: Download byjg/jwt-wrapper 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/ */
byjg / jwt-wrapper example snippets
// Create a JWT token using HMAC
$server = "example.com";
$secret = new \ByJG\JwtWrapper\JwtHashHmacSecret(base64_encode("your_secret_key"));
$jwtWrapper = new \ByJG\JwtWrapper\JwtWrapper($server, $secret);
// Add custom data and set expiration
$token = $jwtWrapper->generateToken(
$jwtWrapper->createJwtData(["userId" => 123], 3600)
);
// Validate and extract data
try {
$jwtData = $jwtWrapper->extractData($token);
$userId = $jwtData->data->userId;
} catch (\ByJG\JwtWrapper\JwtWrapperException $e) {
// Handle invalid token
}
mermaid
flowchart TD
byjg/jwt-wrapper --> firebase/php-jwt
byjg/jwt-wrapper --> ext-openssl