Skip to content

Instantly share code, notes, and snippets.

@lokamaya
Forked from douglascabral/jwt.php
Created March 23, 2019 05:19
Show Gist options
  • Save lokamaya/fcc7622ec8f5a1ea5cbb554268341598 to your computer and use it in GitHub Desktop.
Save lokamaya/fcc7622ec8f5a1ea5cbb554268341598 to your computer and use it in GitHub Desktop.
Example of JWT with Pure PHP
<?php
$key = 'your-secret-key-here';
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
$header = json_encode($header);
$header = base64_encode($header);
$payload = [
'iss' => 'douglascabral.com.br',
'username' => 'douglascabral',
'email' => 'contato@douglascabral.com.br'
];
$payload = json_encode($payload);
$payload = base64_encode($payload);
$signature = hash_hmac('sha256', "{$header}.{$payload}", $key, true);
$signature = base64_encode($signature);
$token = "{$header}.{$payload}.{$signature}";
echo $token;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment