Skip to content

Commit a72158c

Browse files
committed
Allows multiple values for 'iss'
1 parent 8766f13 commit a72158c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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_jwt.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ 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+
350361
def test_iss_invalid(self, key):
351362

352363
iss = 'issuer'

0 commit comments

Comments
 (0)