Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating custom token fails #55

Open
guyyosan opened this issue Dec 6, 2022 · 1 comment
Open

Creating custom token fails #55

guyyosan opened this issue Dec 6, 2022 · 1 comment

Comments

@guyyosan
Copy link

guyyosan commented Dec 6, 2022

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!
@AsifArmanRahman
Copy link

AsifArmanRahman commented Dec 7, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants