MCPcopy
hub / github.com/authlib/authlib / decode

Method decode

authlib/jose/rfc7519/jwt.py:80–114  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
117def decode_payload(bytes_payload):

Callers 15

validate_claimsFunction · 0.95
test_use_jweFunction · 0.95
authenticate_tokenMethod · 0.80
authenticate_tokenMethod · 0.80
extract_headerFunction · 0.80
encode_id_tokenMethod · 0.80

Calls 5

to_bytesFunction · 0.90
create_load_keyFunction · 0.85
prepare_raw_keyFunction · 0.85
DecodeErrorClass · 0.85
deserialize_compactMethod · 0.45

Tested by 15

validate_claimsFunction · 0.76
test_use_jweFunction · 0.76
sign_and_decodeFunction · 0.64
test_sign_with_ec_keyFunction · 0.64
sign_and_decodeFunction · 0.64
test_authorize_tokenFunction · 0.64