NabuCasa / pycognito

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
126 stars 38 forks source link

Compatibility Fixes for PyJWT/Cryptography Versions #222

Closed jrschiestle closed 1 month ago

jrschiestle commented 4 months ago

Added compatibility fixes for different byte vs str inputs and outputs. Prevents TypeErrors seen with:

morbitech1 commented 4 weeks ago

Note the issue still seems to be active, and this is using

See below the trace

File "/usr/local/lib/python3.11/site-packages/pycognito/__init__.py", line 704, in renew_access_token
self._set_tokens(refresh_response)
File "/usr/local/lib/python3.11/site-packages/pycognito/__init__.py", line 779, in _set_tokens
self.verify_token(tokens["AuthenticationResult"]["IdToken"], "id_token", "id")
File "/usr/local/lib/python3.11/site-packages/pycognito/__init__.py", line 289, in verify_token
digest = alg_obj.compute_hash_digest(self.access_token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jwt/algorithms.py", line 168, in compute_hash_digest
digest.update(bytestr)
TypeError: argument 'data': from_buffer() cannot return the address of a unicode object

Minimal amount of code to reproduce the issue

import jwt

access_token = ''
alg_obj = jwt.get_algorithm_by_name('RS256')
digest = alg_obj.compute_hash_digest(access_token)
tomjridge commented 1 week ago

I just hit this issue too.