Skip to content

Commit

Permalink
Allows multiple values for 'iss'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmc committed Jul 27, 2016
1 parent 8766f13 commit a72158c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 8 additions & 5 deletions jose/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def decode(token, key, algorithms=None, options=None, audience=None,
audience (str): The intended audience of the token. If the "aud" claim is
included in the claim set, then the audience must be included and must equal
the provided claim.
issuer (str): The issuer of the token. If the "iss" claim is
included in the claim set, then the issuer must be included and must equal
the provided claim.
issuer (str or iterable): Acceptable value(s) for the issuer of the token.
If the "iss" claim is included in the claim set, then the issuer must be
given and the claim in the token must be among the acceptable values.
subject (str): The subject of the token. If the "sub" claim is
included in the claim set, then the subject must be included and must equal
the provided claim.
Expand Down Expand Up @@ -345,11 +345,14 @@ def _validate_iss(claims, issuer=None):
Args:
claims (dict): The claims dictionary to validate.
issuer (str): The issuer that sent the token.
issuer (str or iterable): Acceptable value(s) for the issuer that
signed the token.
"""

if issuer is not None:
if claims.get('iss') != issuer:
if isinstance(issuer, string_types):
issuer = [issuer]
if claims.get('iss') not in issuer:
raise JWTClaimsError('Invalid issuer')


Expand Down
11 changes: 11 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ def test_iss_string(self, key):
token = jwt.encode(claims, key)
jwt.decode(token, key, issuer=iss)

def test_iss_list(self, key):

iss = 'issuer'

claims = {
'iss': iss
}

token = jwt.encode(claims, key)
jwt.decode(token, key, issuer=['https://issuer', 'issuer'])

def test_iss_invalid(self, key):

iss = 'issuer'
Expand Down

0 comments on commit a72158c

Please sign in to comment.