Last active
July 25, 2023 03:44
-
-
Save douglascabral/75436a343575a58a780e79b9457921c0 to your computer and use it in GitHub Desktop.
Example of JWT with Pure PHP
This file contains hidden or 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 | |
$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' => '[email protected]' | |
]; | |
$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; |
Cara, tentei validar seu token e não deu certo. Acho que estou cometendo algum erro, pq eu segui o vídeo do Vedovelli tbm e ao validar tbm deu erro.
Os dados do header e payload aparecem certinho, é a validação do token que não dá certo.
Obrigado.
Tks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!