Decode the JWT with the given key. This is similar with :meth:`verify`, except that it will raise BadSignatureError when signature doesn't match. :param s: text of JWT :param key: key used to verify the signature :param claims_cls: class to be used for JWT cl
(self, s, key, claims_cls=None, claims_options=None, claims_params=None)
| 78 | return self._jws.serialize_compact(header, text, key) |
| 79 | |
| 80 | def decode(self, s, key, claims_cls=None, claims_options=None, claims_params=None): |
| 81 | """Decode the JWT with the given key. This is similar with |
| 82 | :meth:`verify`, except that it will raise BadSignatureError when |
| 83 | signature doesn't match. |
| 84 | |
| 85 | :param s: text of JWT |
| 86 | :param key: key used to verify the signature |
| 87 | :param claims_cls: class to be used for JWT claims |
| 88 | :param claims_options: `options` parameters for claims_cls |
| 89 | :param claims_params: `params` parameters for claims_cls |
| 90 | :return: claims_cls instance |
| 91 | :raise: BadSignatureError |
| 92 | """ |
| 93 | if claims_cls is None: |
| 94 | claims_cls = JWTClaims |
| 95 | |
| 96 | if callable(key): |
| 97 | load_key = key |
| 98 | else: |
| 99 | load_key = create_load_key(prepare_raw_key(key)) |
| 100 | |
| 101 | s = to_bytes(s) |
| 102 | dot_count = s.count(b".") |
| 103 | if dot_count == 2: |
| 104 | data = self._jws.deserialize_compact(s, load_key, decode_payload) |
| 105 | elif dot_count == 4: |
| 106 | data = self._jwe.deserialize_compact(s, load_key, decode_payload) |
| 107 | else: |
| 108 | raise DecodeError("Invalid input segments length") |
| 109 | return claims_cls( |
| 110 | data["payload"], |
| 111 | data["header"], |
| 112 | options=claims_options, |
| 113 | params=claims_params, |
| 114 | ) |
| 115 | |
| 116 | |
| 117 | def decode_payload(bytes_payload): |