From 894539ec9c5345ab1d9c06f3b9492754819a411a Mon Sep 17 00:00:00 2001 From: kadabusha <47604788+kadabusha@users.noreply.github.com> Date: Wed, 29 Dec 2021 22:48:27 +0200 Subject: [PATCH 1/4] Fix for headers disorder issue Related issue #715 --- jwt/api_jws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jwt/api_jws.py b/jwt/api_jws.py index 9e8e1787..a3b5de9d 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -100,7 +100,7 @@ def encode( del header["typ"] json_header = json.dumps( - header, separators=(",", ":"), cls=json_encoder + header, separators=(",", ":"), cls=json_encoder, sort_keys=True ).encode() segments.append(base64url_encode(json_header)) From 4558f6c94c6ab633ab92cd9947c58a39940b983f Mon Sep 17 00:00:00 2001 From: kadabusha <47604788+kadabusha@users.noreply.github.com> Date: Mon, 18 Jul 2022 09:49:28 +0300 Subject: [PATCH 2/4] Added comment with reference to issue Needed to trigger tests once more time. --- jwt/api_jws.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jwt/api_jws.py b/jwt/api_jws.py index a3b5de9d..c328d9b3 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -99,6 +99,7 @@ def encode( if not header["typ"]: del header["typ"] + # Fix for headers misorder - issue #715 json_header = json.dumps( header, separators=(",", ":"), cls=json_encoder, sort_keys=True ).encode() From b0d4830fa2076479be7954c743eec413651c3702 Mon Sep 17 00:00:00 2001 From: kadabusha Date: Mon, 18 Jul 2022 22:25:57 -0700 Subject: [PATCH 3/4] Fix for hardcoded value in docs after adding sort to jwt/api_jws.py --- README.rst | 3 ++- docs/index.rst | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 49aa77a8..4bedaefb 100644 --- a/README.rst +++ b/README.rst @@ -42,7 +42,8 @@ Usage >>> import jwt >>> encoded = jwt.encode({"some": "payload"}, "secret", algorithm="HS256") >>> print(encoded) - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U + eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg +# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U >>> jwt.decode(encoded, "secret", algorithms=["HS256"]) {'some': 'payload'} diff --git a/docs/index.rst b/docs/index.rst index 63e67945..5a4a8636 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,7 +32,8 @@ Example Usage >>> import jwt >>> encoded_jwt = jwt.encode({"some": "payload"}, "secret", algorithm="HS256") >>> print(encoded_jwt) - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U + eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg +# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U >>> jwt.decode(encoded_jwt, "secret", algorithms=["HS256"]) {'some': 'payload'} From 10bc859a2e7bb8b60cce3aa734a1d27c860281b4 Mon Sep 17 00:00:00 2001 From: kadabusha Date: Mon, 18 Jul 2022 22:33:33 -0700 Subject: [PATCH 4/4] Removed unneeded comment - issue #721 --- README.rst | 1 - docs/index.rst | 1 - 2 files changed, 2 deletions(-) diff --git a/README.rst b/README.rst index 4bedaefb..432631e7 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,6 @@ Usage >>> encoded = jwt.encode({"some": "payload"}, "secret", algorithm="HS256") >>> print(encoded) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg -# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U >>> jwt.decode(encoded, "secret", algorithms=["HS256"]) {'some': 'payload'} diff --git a/docs/index.rst b/docs/index.rst index 5a4a8636..5cdf5654 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -33,7 +33,6 @@ Example Usage >>> encoded_jwt = jwt.encode({"some": "payload"}, "secret", algorithm="HS256") >>> print(encoded_jwt) eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg -# eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U >>> jwt.decode(encoded_jwt, "secret", algorithms=["HS256"]) {'some': 'payload'}