Improve documentation for symmetric keys
izolate opened this issue · 2 comments
izolate commented
The README states that symmetric algorithms are supported but I haven't been able to figure out how to decode them with this library. Either I'm missing something or this hasn't been implemented yet.
Either way, appreciate any help on this.
yosida95 commented
You can decode a JWS signed by a symmetric key in the same way to decode one signed by a asymmetric key like below.
import jwt
jwk = {"kty": "oct", "k": "# YOUR SYMMETRIC JWK KEY #"}
key = jwt.jwk_from_dict(jwk)
instance = jwt.JWT()
instance.decode('JWT PAYLOAD', key)
You can also refer to the working test case at
python-jwt/jwt/tests/test_jwt.py
Lines 26 to 50 in 6e45f9d
yosida95 commented
Or you can also instantiate symmetric JWK directly as below.
import jwt
from jwt.jwk import OctetJWK
key = OctetJWK(b'SYMMETRIC KEY')
instance = jwt.JWT()
instance.decode('JWT PAYLOAD', key)