-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge develop branch. Release v0.2.0
- Loading branch information
Showing
11 changed files
with
342 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# IDE generated files | ||
.vscode/ | ||
|
||
# Python generated files | ||
__pycache__/ | ||
*.pyc | ||
.pytest_cache | ||
|
||
# Packaging generated files | ||
*.egg-info | ||
build/ | ||
dist/ | ||
|
||
# Tox | ||
.tox | ||
|
||
# Code coverage | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
# OKTA JWT Verifier Changelog | ||
|
||
## v0.2.0 | ||
- Add classes IDTokenVerifier and AccessTokenVerifier | ||
- Mark JWTVerifier class as deprecated. This class will be removed in the next major version. | ||
- Add proxy support | ||
- Update README | ||
- Few codebase improvements | ||
|
||
_New features:_ | ||
- Separate classes for verifying ID Tokens and Access Tokens | ||
- Add proxy support | ||
|
||
## v0.1.0 | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,7 @@ publish\:test: | |
|
||
publish\:prod: | ||
python3 -m twine upload dist/* | ||
|
||
test: | ||
@echo "Run unittests" | ||
pytest tests/unit/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
|
||
from jose import jwt, jws | ||
|
||
from .constants import LEEWAY | ||
from .exceptions import JWTValidationException | ||
|
||
|
||
class JWTUtils: | ||
"""Contains different utils and common methods for jwt verification.""" | ||
|
||
@staticmethod | ||
def parse_token(token): | ||
"""Parse JWT token, get headers, claims and signature. | ||
Return: | ||
tuple (headers, claims, signing_input, signature) | ||
""" | ||
headers, payload, signing_input, signature = jws._load(token) | ||
claims = json.loads(payload.decode('utf-8')) | ||
return (headers, claims, signing_input, signature) | ||
|
||
@staticmethod | ||
def verify_claims(claims, | ||
claims_to_verify, | ||
audience, | ||
issuer, | ||
leeway=LEEWAY): | ||
"""Verify claims are present and valid.""" | ||
# Check if required claims are present, because library "jose" doesn't raise an exception | ||
for claim in claims_to_verify: | ||
if claim not in claims: | ||
raise JWTValidationException(f'Required claim "{claim}" is not present.') | ||
|
||
# Overwrite defaults in python-jose library | ||
options = {'verify_aud': 'aud' in claims_to_verify, | ||
'verify_iat': 'iat' in claims_to_verify, | ||
'verify_exp': 'exp' in claims_to_verify, | ||
'verify_nbf': 'nbf' in claims_to_verify, | ||
'verify_iss': 'iss' in claims_to_verify, | ||
'verify_sub': 'sub' in claims_to_verify, | ||
'verify_jti': 'jti' in claims_to_verify, | ||
'leeway': leeway} | ||
# Validate claims | ||
jwt._validate_claims(claims, | ||
audience=audience, | ||
issuer=issuer, | ||
options=options) | ||
|
||
@staticmethod | ||
def verify_signature(token, okta_jwk): | ||
"""Verify token signature using received jwk.""" | ||
headers, claims, signing_input, signature = JWTUtils.parse_token(token) | ||
jws._verify_signature(signing_input=signing_input, | ||
header=headers, | ||
signature=signature, | ||
key=okta_jwk, | ||
algorithms=['RS256']) | ||
|
||
@staticmethod | ||
def verify_expiration(token, leeway=LEEWAY): | ||
"""Verify if token is not expired.""" | ||
headers, claims, signing_input, signature = JWTUtils.parse_token(token) | ||
JWTUtils.verify_claims(claims, claims_to_verify=('exp'), leeway=LEEWAY) |
Oops, something went wrong.