3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * SIMPLE JWT TOKEN GENERATOR FOR C# API GATEWAY * * Quick setup: * 1. Run: composer install * 2. Update the $clientSecret variable below * 3. Run: php simple_jwt_example.php */ require_once 'vendor/autoload.php'; // ======================================== // CONFIGURATION (Match your Program.cs) // ======================================== $issuer = "https://abc.com/authservice"; $audience = "https://abc.com/megamart"; $clientSecret = "YOUR_SECRET_KEY_HERE"; // ⚠️ MUST MATCH Line 5 in Program.cs! // ======================================== // CREATE TOKEN // ======================================== $payload = [ 'iss' => $issuer, // Issuer 'aud' => $audience, // Audience 'iat' => time(), // Issued at 'nbf' => time(), // Not before 'exp' => time() + (60 * 60), // Expires in 1 hour // Custom claims (your user data) 'sub' => '12345', // User ID 'name' => 'John Doe', 'email' => 'john.doe@example.com', 'role' => 'Admin' ]; $jwt = JWT::encode($payload, $clientSecret, 'HS256'); // ======================================== // OUTPUT // ======================================== echo "JWT Token Generated:\n"; echo "====================\n\n"; echo $jwt . "\n\n"; ?> <?php /** * SIMPLE JWT TOKEN GENERATOR FOR C# API GATEWAY * * Quick setup: * 1. Run: composer install * 2. Update the $clientSecret variable below * 3. Run: php simple_jwt_example.php */ require_once 'vendor/autoload.php'; use Firebase\JWT\JWT; // ======================================== // CONFIGURATION (Match your Program.cs) // ======================================== $issuer = "https://abc.com/authservice"; $audience = "https://abc.com/megamart"; $clientSecret = "YOUR_SECRET_KEY_HERE"; // ⚠️ MUST MATCH Line 5 in Program.cs! // ======================================== // CREATE TOKEN // ======================================== $payload = [ 'iss' => $issuer, // Issuer 'aud' => $audience, // Audience 'iat' => time(), // Issued at 'nbf' => time(), // Not before 'exp' => time() + (60 * 60), // Expires in 1 hour // Custom claims (your user data) 'sub' => '12345', // User ID 'name' => 'John Doe', 'email' => 'john.doe@example.com', 'role' => 'Admin' ]; $jwt = JWT::encode($payload, $clientSecret, 'HS256'); // ======================================== // OUTPUT // ======================================== echo "JWT Token Generated:\n"; echo "====================\n\n"; echo $jwt . "\n\n"; ?>
Output for 8.5.0 - 8.5.1
Warning: require_once(vendor/autoload.php): Failed to open stream: No such file or directory in /in/p5J71 on line 11 Fatal error: Uncaught Error: Failed opening required 'vendor/autoload.php' (include_path='.:') in /in/p5J71:11 Stack trace: #0 {main} thrown in /in/p5J71 on line 11
Process exited with code 255.
Output for 8.1.34, 8.2.27 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.16
Warning: require_once(): open_basedir restriction in effect. File(vendor/autoload.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/p5J71 on line 11 Warning: require_once(vendor/autoload.php): Failed to open stream: Operation not permitted in /in/p5J71 on line 11 Fatal error: Uncaught Error: Failed opening required 'vendor/autoload.php' (include_path='.:') in /in/p5J71:11 Stack trace: #0 {main} thrown in /in/p5J71 on line 11
Process exited with code 255.

preferences:
68.24 ms | 408 KiB | 5 Q