Skip to content

Commit 0bef0fb

Browse files
authored
Fix for headers disorder issue (#721)
* Fix for headers disorder issue Related issue #715 * Added comment with reference to issue Needed to trigger tests once more time. * Fix for hardcoded value in docs after adding sort to jwt/api_jws.py * Removed unneeded comment - issue #721
1 parent c8fda69 commit 0bef0fb

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Usage
4242
>>> import jwt
4343
>>> encoded = jwt.encode({"some": "payload"}, "secret", algorithm="HS256")
4444
>>> print(encoded)
45-
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U
45+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg
4646
>>> jwt.decode(encoded, "secret", algorithms=["HS256"])
4747
{'some': 'payload'}
4848

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Example Usage
3232
>>> import jwt
3333
>>> encoded_jwt = jwt.encode({"some": "payload"}, "secret", algorithm="HS256")
3434
>>> print(encoded_jwt)
35-
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U
35+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg
3636
>>> jwt.decode(encoded_jwt, "secret", algorithms=["HS256"])
3737
{'some': 'payload'}
3838

jwt/api_jws.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ def encode(
132132
# True is the standard value for b64, so no need for it
133133
del header["b64"]
134134

135+
# Fix for headers misorder - issue #715
135136
json_header = json.dumps(
136-
header, separators=(",", ":"), cls=json_encoder
137+
header, separators=(",", ":"), cls=json_encoder, sort_keys=True
137138
).encode()
138139

139140
segments.append(base64url_encode(json_header))

0 commit comments

Comments
 (0)