Skip to content

Use PyJWT instead of python-jose #49

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

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 4 additions & 7 deletions intuitlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
from datetime import datetime
import random
import string
from jose import jwk
import requests
from requests.sessions import Session
import six
from requests_oauthlib import OAuth1
from jwt import PyJWKSet


from intuitlib.enums import Scopes
Expand Down Expand Up @@ -165,9 +164,8 @@ def validate_id_token(id_token, client_id, intuit_issuer, jwk_uri):
return False

message = id_token_parts[0] + '.' + id_token_parts[1]
keys_dict = get_jwk(id_token_header['kid'], jwk_uri)
public_key = get_jwk(id_token_header['kid'], jwk_uri).key

public_key = jwk.construct(keys_dict)
is_signature_valid = public_key.verify(message.encode('utf-8'), id_token_signature)
return is_signature_valid

Expand All @@ -178,15 +176,14 @@ def get_jwk(kid, jwk_uri):
:param jwk_uri: JWK URI

:raises HTTPError: if response status != 200
:return: dict containing keys
:return: Algorithm with the key loaded.
"""

response = requests.get(jwk_uri)
if response.status_code != 200:
raise AuthClientError(response)
data = response.json()
keys = next(key for key in data["keys"] if key['kid'] == kid)
return keys
return PyJWKSet.from_dict(data)[kid]

def _correct_padding(val):
"""Correct padding for JWT
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
python_jose>=2.0.2
requests>=2.13.0
mock>=2.0.0
requests_oauthlib>=1.0.0
Expand All @@ -8,3 +7,4 @@ pytest>=3.8.0
pytest-cov==2.5.0
six>=1.10.0
enum-compat
pyjwt[crypto]>=2.0.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
packages=find_packages(exclude=('tests*',)),
namespace_packages=('intuitlib',),
install_requires=[
'python_jose>=2.0.2',
'pyjwt[crypto]>=2.0.0',
'requests>=2.13.0',
'requests_oauthlib>=1.0.0',
'six>=1.10.0',
Expand Down