Skip to content

Commit

Permalink
Use PyJWT instead of python-jose
Browse files Browse the repository at this point in the history
  • Loading branch information
Natim committed May 28, 2024
1 parent 8cefee7 commit 6761ac6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
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)

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
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',
'requests>=2.13.0',
'requests_oauthlib>=1.0.0',
'six>=1.10.0',
Expand Down

0 comments on commit 6761ac6

Please sign in to comment.