Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e355df

Browse files
authored
Merge pull request auth0#273 from bisguzar/patch-1
2 parents fbeab6a + d7e4078 commit 9e355df

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

auth0/v3/authentication/token_verifier.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def verify(self, token, nonce=None, max_age=None, organization=None):
229229
organization (str, optional): The expected organization ID (org_id) claim value. This should be specified
230230
when logging in to an organization.
231231
232+
Returns:
233+
the decoded payload from the token
234+
232235
Raises:
233236
TokenValidationError: when the token cannot be decoded, the token signing algorithm is not the expected one,
234237
the token signature is invalid or the token has a claim missing or with unexpected value.
@@ -244,6 +247,8 @@ def verify(self, token, nonce=None, max_age=None, organization=None):
244247
# Verify claims
245248
self._verify_payload(payload, nonce, max_age, organization)
246249

250+
return payload
251+
247252
def _verify_payload(self, payload, nonce=None, max_age=None, organization=None):
248253
try:
249254
# on Python 2.7, 'str' keys as parsed as 'unicode'

auth0/v3/test/authentication/test_token_verifier.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def test_passes_when_org_present_and_matches(self):
390390
audience=expectations['audience']
391391
)
392392
tv._clock = MOCKED_CLOCK
393-
tv.verify(token, organization='org_123')
393+
tv.verify(token, organization='org_123')
394394

395395
def test_fails_when_org_specified_but_not_present(self):
396396
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhdXRoMHxzZGs0NThma3MiLCJhdWQiOiJ0b2tlbnMtdGVzdC0xMjMiLCJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJleHAiOjE1ODc3NjUzNjEsImlhdCI6MTU4NzU5MjU2MX0.wotJnUdD5IfdZMewF_-BnHc0pI56uwzwr5qaSXvSu9w"
@@ -402,4 +402,22 @@ def test_fails_when_org_specified_but_not_(self):
402402

403403
def test_fails_when_org_specified_but_does_not_match(self):
404404
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhdXRoMHxzZGs0NThma3MiLCJhdWQiOiJ0b2tlbnMtdGVzdC0xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwiaXNzIjoiaHR0cHM6Ly90b2tlbnMtdGVzdC5hdXRoMC5jb20vIiwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjF9.hjSPgJpg0Dn2z0giCdGqVLD5Kmqy_yMYlSkgwKD7ahQ"
405-
self.assert_fails_with_error(token, 'Organization (org_id) claim mismatch in the ID token; expected "org_abc", found "org_123"', signature_verifier=SymmetricSignatureVerifier(HMAC_SHARED_SECRET), organization='org_abc')
405+
self.assert_fails_with_error(token, 'Organization (org_id) claim mismatch in the ID token; expected "org_abc", found "org_123"', signature_verifier=SymmetricSignatureVerifier(HMAC_SHARED_SECRET), organization='org_abc')
406+
407+
def test_verify_returns_payload(self):
408+
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhdXRoMHxzZGs0NThma3MiLCJhdWQiOiJ0b2tlbnMtdGVzdC0xMjMiLCJvcmdfaWQiOiJvcmdfMTIzIiwiaXNzIjoiaHR0cHM6Ly90b2tlbnMtdGVzdC5hdXRoMC5jb20vIiwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjF9.hjSPgJpg0Dn2z0giCdGqVLD5Kmqy_yMYlSkgwKD7ahQ"
409+
sv = SymmetricSignatureVerifier(HMAC_SHARED_SECRET)
410+
tv = TokenVerifier(
411+
signature_verifier=sv,
412+
issuer=expectations['issuer'],
413+
audience=expectations['audience']
414+
)
415+
tv._clock = MOCKED_CLOCK
416+
response = tv.verify(token)
417+
self.assertIn('sub', response);
418+
self.assertIn('aud', response);
419+
self.assertIn('org_id', response);
420+
self.assertIn('iss', response);
421+
self.assertIn('exp', response);
422+
self.assertIn('iat', response);
423+
self.assertEqual('org_123', response['org_id'])

0 commit comments

Comments
 (0)