So I have a client in python and a backend in PHP. The python client is using pyjwt and the php server is using Firebase JWT.
When encoding and decoding tokens within php everything works fine. But when I encode tokens from python and decode them with php the Firebase library returns an error:
Firebase\JWT\SignatureInvalidException Object
(
[message:protected] => Signature verification failed
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/vendor/firebase/php-jwt/src/JWT.php
[line:protected] => 110
...
The encoding python code is the following
import jwt
...
payload = {'sub': self.client.id, 'exp': (datetime.now() + timedelta(days=1)).timestamp()}
context['token'] = jwt.encode(payload, os.environ['JWT_KEY'], algorithm='HS256')
and the PHP code is the following
$key = getenv("JWT_KEY");
return (array) \Firebase\JWT\JWT::decode($token, $key, array('HS256'));
OK, I found the problem. The issue was the secret KEY ussed by the different parties. The key had a problem when trying to be readed by PHP and thats why it was creating different tokens. The libraries are ok, they can communicate between each other without any problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With