Pyrebase4
Pyrebase4 copied to clipboard
Creating custom token fails
Hey, First, thanks for pyrebase.
I was getting the following error/logtrace :
return jwt.generate_jwt(payload, private_key, "RS256", exp)
File "/Users/guyma/development/firebase-poc/venv/lib/python3.10/site-packages/python_jwt/__init__.py", line 91, in generate_jwt
token.add_signature(priv_key, protected=header)
File "/Users/guyma/development/firebase-poc/venv/lib/python3.10/site-packages/jwcrypto/jws.py", line 540, in add_signature
sig = c.sign()
File "/Users/guyma/development/firebase-poc/venv/lib/python3.10/site-packages/jwcrypto/jws.py", line 149, in sign
raise ValueError('key is not a JWK object')
ValueError: key is not a JWK object```
**I managed to solve it locally by replacing line 104~ in pyrebase.py**
from: `private_key = RSA.importKey(self.credentials._private_key_pkcs8_pem)`
to: `private_key = jwk.JWK.from_pem(str.encode(self.credentials._private_key_pkcs8_pem))`
Thank you!
---
Make sure these boxes are checked before submitting your issue:
[V] Check that your version of Python is 3.4+
[V] Check that you are on the newest version of Pyrebase
[V] Check that Email/password provider is enabled in your Firebase dashboard under Auth -> Sign In Method.
Please don't be discouraged if you do not get a response to your issue quickly,
I maintain Pyrebase for fun and don't always have as much free time as I'd like.
Thank you for helping make Pyrebase better!
@guyyosan You can create a pull request if you want. You can also use firebase-rest-api where I've solved the issue using updated dependencies.