Skip to content

Commit cd92a03

Browse files
committed
Fixed improper signature calculation. Was using hexdigest representation of HMAC, when it should be digest.
Based on this issue: https://github.com/progrium/ruby-jwt/issues/#issue/1
1 parent e1002db commit cd92a03

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

jwt/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
class DecodeError(Exception): pass
1818

1919
signing_methods = {
20-
'HS256': lambda msg, key: hmac.new(key, msg, hashlib.sha256).hexdigest(),
21-
'HS384': lambda msg, key: hmac.new(key, msg, hashlib.sha384).hexdigest(),
22-
'HS512': lambda msg, key: hmac.new(key, msg, hashlib.sha512).hexdigest(),
20+
'HS256': lambda msg, key: hmac.new(key, msg, hashlib.sha256).digest(),
21+
'HS384': lambda msg, key: hmac.new(key, msg, hashlib.sha384).digest(),
22+
'HS512': lambda msg, key: hmac.new(key, msg, hashlib.sha512).digest(),
2323
}
2424

2525
def base64url_decode(input):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def read(fname):
66

77
setup(
88
name = "PyJWT",
9-
version = "0.1.1",
9+
version = "0.1.2",
1010
author = "Jeff Lindsay",
1111
author_email = "jeff.lindsay@twilio.com",
1212
description = ("JSON Web Token implemtnation in Python"),

tests/test_jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_bad_secret(self):
2323
def test_decodes_valid_jwt(self):
2424
example_payload = {"hello": "world"}
2525
example_secret = "secret"
26-
example_jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.YjZmNmEwMmMzMmU4NmEyMjRhYzRlMmFhYTQxNWQyMTA2Y2JiNDk4NGEyN2Q5ODYzOWVkODI2ZjVjYjY5Y2EzZg"
26+
example_jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8"
2727
decoded_payload = jwt.decode(example_jwt, example_secret)
2828
self.assertEqual(decoded_payload, example_payload)
2929

0 commit comments

Comments
 (0)