Skip to content

Instantly share code, notes, and snippets.

@magicien
Created September 9, 2017 22:06
Show Gist options
  • Save magicien/2851bf74c4626d66cec7603c11f1a1eb to your computer and use it in GitHub Desktop.
Save magicien/2851bf74c4626d66cec7603c11f1a1eb to your computer and use it in GitHub Desktop.
How to create JWT with lcobucci/jwt in PHP
<?php
require_once('../composer/vendor/autoload.php');
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Rsa\Sha256;
$signer = new Sha256();
$key = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
HogeHogeHogeHoge....
-----END RSA PRIVATE KEY-----
EOT;
$token = (new Builder())->setIssuedAt(time())
->setExpiration(time() + 600) // maximum: 600s
->setIssuer("1234567890") // App ID
->sign($signer, $key)
->getToken();
$token->getHeaders();
$token->getClaims();
echo $token;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment