Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for checking against multiple issuers #308

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ Patches and Suggestions
- Michael Davis <mike.philip.davis@gmail.com> <mike.davis@workiva.com>

- Vinod Gupta <codervinod@gmail.com>

- Jason Quense <monastic.panic@gmail.com>
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Audience parameter now supports iterables [#205][205]

- Issuer parameter now supports iterables [#308][308]

### Fixed

### Added
Expand Down Expand Up @@ -205,3 +207,6 @@ rarely used. Users affected by this should upgrade to 3.3+.
[277]: https://github.com/jpadilla/pyjwt/pull/277
[281]: https://github.com/jpadilla/pyjwt/pull/281
[7c1e61d]: https://github.com/jpadilla/pyjwt/commit/7c1e61dde27bafe16e7d1bb6e35199e778962742
[297]: https://github.com/jpadilla/pyjwt/pull/297
[205]: https://github.com/jpadilla/pyjwt/pull/205
[308]: https://github.com/jpadilla/pyjwt/pull/308
5 changes: 4 additions & 1 deletion jwt/api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ def _validate_iss(self, payload, issuer):
if 'iss' not in payload:
raise MissingRequiredClaimError('iss')

if payload['iss'] != issuer:
if isinstance(issuer, string_types):
issuer = [issuer]

if payload['iss'] not in issuer:
raise InvalidIssuerError('Invalid issuer')


Expand Down
17 changes: 17 additions & 0 deletions tests/test_api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ def test_check_issuer_when_valid(self, jwt):
token = jwt.encode(payload, 'secret')
jwt.decode(token, 'secret', issuer=issuer)

def test_check_issuer_list_when_valid(self, jwt):
payload = {
'some': 'payload',
'iss': 'urn:me'
}
token = jwt.encode(payload, 'secret')
jwt.decode(token, 'secret', issuer=['urn:you', 'urn:me'])

def test_raise_exception_invalid_issuer(self, jwt):
issuer = 'urn:wrong'

Expand All @@ -374,6 +382,15 @@ def test_raise_exception_invalid_issuer(self, jwt):
with pytest.raises(InvalidIssuerError):
jwt.decode(token, 'secret', issuer=issuer)

def test_raise_exception_invalid_issuer_list(self, jwt):
payload = {
'some': 'payload',
'iss': 'urn:me'
}
token = jwt.encode(payload, 'secret')
with pytest.raises(InvalidIssuerError):
jwt.decode(token, 'secret', issuer=['urn:you', 'urn:him'])

def test_skip_check_audience(self, jwt):
payload = {
'some': 'payload',
Expand Down