Skip to content

Commit 2055f0a

Browse files
author
Michael Davis
authored
Merge pull request #31 from bjmc/multiple_iss
Allows multiple values for 'iss'
2 parents 8766f13 + 2cf888f commit 2055f0a

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

jose/jws.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def _get_keys(key):
222222
elif (isinstance(key, Iterable) and
223223
not (isinstance(key, six.string_types) or isinstance(key, Mapping))):
224224
return key
225-
else: # Scalar value, wrap in list.
226-
return [key]
225+
else: # Scalar value, wrap in tuple.
226+
return (key,)
227227

228228

229229
def _verify_signature(signing_input, header, signature, key='', algorithms=None):

jose/jwt.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def decode(token, key, algorithms=None, options=None, audience=None,
7272
audience (str): The intended audience of the token. If the "aud" claim is
7373
included in the claim set, then the audience must be included and must equal
7474
the provided claim.
75-
issuer (str): The issuer of the token. If the "iss" claim is
76-
included in the claim set, then the issuer must be included and must equal
77-
the provided claim.
75+
issuer (str or iterable): Acceptable value(s) for the issuer of the token.
76+
If the "iss" claim is included in the claim set, then the issuer must be
77+
given and the claim in the token must be among the acceptable values.
7878
subject (str): The subject of the token. If the "sub" claim is
7979
included in the claim set, then the subject must be included and must equal
8080
the provided claim.
@@ -345,11 +345,14 @@ def _validate_iss(claims, issuer=None):
345345
346346
Args:
347347
claims (dict): The claims dictionary to validate.
348-
issuer (str): The issuer that sent the token.
348+
issuer (str or iterable): Acceptable value(s) for the issuer that
349+
signed the token.
349350
"""
350351

351352
if issuer is not None:
352-
if claims.get('iss') != issuer:
353+
if isinstance(issuer, string_types):
354+
issuer = (issuer,)
355+
if claims.get('iss') not in issuer:
353356
raise JWTClaimsError('Invalid issuer')
354357

355358

tests/test_jws.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ def jwk_set():
201201
class TestGetKeys(object):
202202

203203
def test_dict(self):
204-
assert [{}] == jws._get_keys({})
204+
assert ({},) == jws._get_keys({})
205205

206206
def test_custom_object(self):
207207
class MyDict(dict):
208208
pass
209209
mydict = MyDict()
210-
assert [mydict] == jws._get_keys(mydict)
210+
assert (mydict,) == jws._get_keys(mydict)
211211

212212
def test_RFC7517_string(self):
213213
key = '{"keys": [{}, {}]}'
@@ -218,7 +218,7 @@ def test_RFC7517_mapping(self):
218218
assert [{}, {}] == jws._get_keys(key)
219219

220220
def test_string(self):
221-
assert ['test'] == jws._get_keys('test')
221+
assert ('test',) == jws._get_keys('test')
222222

223223
def test_tuple(self):
224224
assert ('test', 'key') == jws._get_keys(('test', 'key'))

tests/test_jwt.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,28 @@ def test_iss_string(self, key):
347347
token = jwt.encode(claims, key)
348348
jwt.decode(token, key, issuer=iss)
349349

350+
def test_iss_list(self, key):
351+
352+
iss = 'issuer'
353+
354+
claims = {
355+
'iss': iss
356+
}
357+
358+
token = jwt.encode(claims, key)
359+
jwt.decode(token, key, issuer=['https://issuer', 'issuer'])
360+
361+
def test_iss_tuple(self, key):
362+
363+
iss = 'issuer'
364+
365+
claims = {
366+
'iss': iss
367+
}
368+
369+
token = jwt.encode(claims, key)
370+
jwt.decode(token, key, issuer=('https://issuer', 'issuer'))
371+
350372
def test_iss_invalid(self, key):
351373

352374
iss = 'issuer'

0 commit comments

Comments
 (0)