Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cryptojwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from binascii import unhexlify

__version__ = '0.3.0'
__version__ = '0.3.1'

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/cryptojwt/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def pick_key(keys, use, alg='', key_type='', kid=''):
continue

if key.kty == key_type:
if key.alg == '' or key.alg == alg:
if key.alg == '' or alg == '' or key.alg == alg:
if key.kid == '' or kid == '' or key.kid == kid:
res.append(key)
return res
Expand Down
27 changes: 27 additions & 0 deletions tests/test_5_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ def test_jwt_pack_encrypt_no_sign():
info = bob.unpack(_jwt)

assert set(info.keys()) == {'iat', 'iss', 'sub', 'aud'}


def test_jwt_pack_and_unpack_with_alg():
alice = JWT(own_keys=ALICE_KEYS, iss=ALICE)
payload = {'sub': 'sub'}
_jwt = alice.pack(payload=payload)

from cryptojwt.jwk import KEYS
alice_jwks = {
"keys":
[{
"kty": "RSA",
"alg": "RS256",
"use": "sig",
"kid": "1",
"n": ALICE_PUB_KEYS[0].n,
"e": ALICE_PUB_KEYS[0].e
}]
}
alg_keys = KEYS()
alg_keys.load_dict(alice_jwks)

bob = JWT(rec_keys={ALICE: alg_keys})
info = bob.unpack(_jwt)

assert set(info.keys()) == {'iat', 'iss', 'sub', 'kid', 'aud'}