Auth0 Home Blog Docs

Jwt.io can't validate JWT with valid key

lock

#1

Can’t validate the JWT using the key.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJsb2NhbGhvc3QiLCJuYW1lIjoiRGlvZ28iLCJlbWFpbCI6ImRpb2dvLmZyYWdhYmVtZmljYUBnbWFpbC5jb20ifQ==.rXrDC+Fk9p8yxwvaodFa6oN+1XpsVHtWZN+hDG7XefE=

The key for the JWT above is ‘minha-esponja’, but it is not working.

Follow my PHP code:

<?php

$key = ‘minha-esponja’;

$header = [
‘alg’ => ‘HS256’,
‘typ’ => ‘JWT’
];

$header = json_encode($header);

$header = base64_encode($header);

$payload = [
‘iss’ => ‘localhost’,
‘name’ => ‘Diogo’,
‘email’ => ‘diogo.fragabemfica@gmail.com’
];

$payload = json_encode($payload);

$payload = base64_encode($payload);

$signature = hash_hmac(‘sha256’,"$header.$payload", $key,true);

$signature = base64_encode($signature);

echo “$header.$payload.$signature”;

echo ‘

’;

$token = “$header.$payload.$signature”;

echo $token;