Created
September 9, 2017 22:06
-
-
Save magicien/2851bf74c4626d66cec7603c11f1a1eb to your computer and use it in GitHub Desktop.
How to create JWT with lcobucci/jwt in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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